home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 April / enter-2004-04.iso / files / httrack-3.30.exe / {app} / src_win / WinHTTrack / Shell.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2003-07-06  |  102.0 KB  |  2,962 lines

  1. // Shell.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. // thread windows
  5. #include <process.h>
  6.  
  7. #include "stdafx.h"
  8. #include "Shell.h"
  9. #include "NewProj.h"
  10.  
  11. #include "htsbase.h"
  12.  
  13. // Ras
  14. #if USE_RAS 
  15. #include "RasLoad.h"
  16. #endif
  17.  
  18. #include <afxdisp.h>
  19. #include "ras.h"
  20.  
  21. //#include "ShellDoc.h"
  22. //#include "ShellView.h"
  23.  
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29.  
  30. // PATCH-->
  31. // PATCH-->
  32. #include "about.h"
  33. #include "infoend.h"
  34.  
  35. // flag de termination
  36. int termine=0;
  37. int termine_requested=0;
  38. int shell_terminated=0;
  39. int soft_term_requested=0;
  40. FILE* fp_debug=NULL;
  41.  
  42. #include "stdafx.h"
  43. #include "Shell.h"
  44. #include "process.h"
  45. //#include "ShellDoc.h"
  46. //#include "ShellView.h"
  47. //#include "essai.h"
  48. //#include "get.h"
  49. //#include "parameter.h"
  50. extern "C" {
  51.   #include "htssystem.h"
  52. }
  53. #include "Wid1.h"
  54. #include "trans.h"
  55. #include "InfoUrl.h"
  56. //#include "option.h"
  57. //#include "filter.h"
  58. //#include "wizard.h"
  59. //
  60. #include "maintab.h"
  61. //
  62. #include "MemRegister.h"
  63.  
  64. // LANG
  65. #include "newlang.h"
  66.  
  67.  
  68. // PATCH-->
  69. //#include "wizard2.h"
  70. //#include "WizLinks.h"
  71.  
  72. #include "inprogress.h"
  73.  
  74. #include "SYS\TIMEB.H"
  75.  
  76. // htswrap_add
  77. extern "C" {
  78.   #include "htswrap.h"
  79. };
  80.  
  81. // --- --- --- --- Options --- --- --- ---
  82.  
  83. #define MAX_LEN_INPROGRESS 32
  84.  
  85. // lancement en multithread du shell ET de gethostbyname
  86. #define SHELL_MULTITHREAD 1
  87. //#define HTS_XGMETHOD 2    // 1: AfxBeginThread 2: _beginthread
  88. // --- --- --- --- Options --- --- --- ---
  89. //int INREDRAW_LOCKED=0;      // refresh graphique en cours
  90. //int INFILLMEM_LOCKED=0;     // refresh mΘmoire en cours
  91. int HTTRACK_result=0;
  92. //
  93. CInfoUrl* _Cinprogress_inst=NULL;
  94.  
  95. extern HICON httrack_icon;
  96.  
  97. /* Main splitter frame */
  98. #include "DialogContainer.h"
  99. #include "splitter.h"
  100. extern CSplitterFrame* this_CSplitterFrame;
  101.  
  102. /* Main WizTab frame */
  103. #include "WizTab.h"
  104. extern CWizTab* this_CWizTab;
  105. /* Argh - pas de domodal dans des autres threads ?!?! */
  106. char WIZ_question[1000];
  107. char WIZ_reponse[1000];
  108.  
  109.  
  110. // Fonctionnement des THREADS:
  111. //
  112. // principal ---> robot & refresh data (thread 1)
  113. //           ---> refresh graphique    (thread 2)
  114. //           GO!> boucle gestion domodal() et boutons
  115. // arrΩt: principal demande l'arrΩt (termine_requested)
  116. //        thread1 active termine et que thread2 ait fini de refresher
  117. //        thread2 se termine
  118. //        thread1 retourne 0 α hts_loop
  119. //        le robot termine
  120. //        le thread1 active termine, termine le formulaire et se termine
  121. //        principal ayant quittΘ le formulaire affiche le message de fin
  122.  
  123.  
  124. // htslib.c
  125. extern "C" {
  126.   HTSEXT_API void qsec2str(char *st,TStamp t);
  127. }
  128.  
  129. // construction index gΘnΘral
  130. // void Build_TopIndex();
  131.  
  132. void compute_options() ;
  133. char* connversion(char chaine[10000]);
  134. void lance(void);
  135. int check_continue(char* pathlog);
  136. int inprogress_refresh();
  137. //int inprogress_refresh_scan();
  138. void Write_profile(CString path,int load_path);
  139. void Read_profile(CString path,int load_path);
  140.  
  141.  
  142. // dΘja fait mais bon
  143. #define HTS_WIN 1
  144.  
  145. extern "C" {
  146.   #include "htscore.h"
  147. }
  148.  
  149. CString _HTTRACK_VERSION = HTTRACK_VERSION;
  150.  
  151. char LINE[32768];
  152. char OPTIONurl[32000];
  153. char OPTIONfilelist[HTS_URLMAXSIZE*2];
  154. char OPTIONproxy[500];
  155. char OPTIONproxyftp[8];
  156. char OPTIONport[100];
  157. char OPTIONdepth[20];
  158. char OPTIONextdepth[20];
  159. char OPTIONget[10];
  160. //char OPTIONlevel[10];
  161. char OPTIONwhere[8];
  162. char OPTIONmeth[8];
  163. char OPTIONmaxfile[100];
  164. char OPTIONmax[100];
  165. char OPTIONfrag[100];
  166. char OPTIONconn[100];
  167. char OPTIONtog[10];
  168. char OPTIONcache[8];
  169. char OPTIONrobots[8];
  170. char choixdeb[8];
  171. char build[256];
  172. char filtre[32];
  173. char OPTIONhtmlfirst[8];
  174. char OPTIONindex[8];
  175. char OPTIONindex2[8];
  176. char OPTIONdos[8];
  177. char OPTIONtime[20];
  178. char OPTIONrate[20];
  179. char OPTIONhostquit[20];
  180. char OPTIONka[20];
  181. char OPTIONuser[256];
  182. char OPTIONfooter[256];
  183. char OPTIONlog[8];
  184. char OPTIONtestall[8];
  185. char OPTIONparseall[8];
  186. char OPTIONlink[8];
  187. char OPTIONpath[1000];
  188. char OPTIONretry[16];
  189. char OPTIONerrpage[8];
  190. char OPTIONexternal[8];
  191. char OPTIONnopurge[8];
  192. char OPTIONhidepwd[8];
  193. char OPTIONhidequery[8];
  194. char OPTIONcookies[8];
  195. char OPTIONchecktype[8];
  196. char OPTIONparsejava[8];
  197. char OPTIONCache2[8];
  198. char OPTIONlogtype[8];
  199. char OPTIONnorecatch[8];
  200. char OPTIONtoler[8];
  201. char OPTIONupdhack[8];
  202. char OPTIONhttp10[8];
  203. //-->
  204. char OPTIONwaittime[32];
  205. char OPTIONmaxtime[32];
  206. char OPTIONmaxrate[32];
  207. char OPTIONmaxconn[32];
  208. char OPTIONmaxlinks[32];
  209. char OPTIONhh[32];
  210. char OPTIONmm[32];
  211. char OPTIONss[32];
  212. //
  213. char buff_filtres[8192];
  214. char buff_MIME[8192];
  215. // RAS
  216. char OPTION_RasString[256];
  217. RASDIALPARAMS OPTION_dial;
  218.  
  219. // Fichier tempo
  220. FILE* tmpf=NULL;
  221. MemRegister tmpm;
  222.  
  223. CNewProj* dialog0=NULL;
  224. Wid1* dialog1=NULL;
  225. Ctrans* dialog2=NULL;
  226. //Coption dialog3;
  227. //Cfilter diafiltre;
  228. /*
  229. wizard diawiz;
  230. wizard2 diawiz2;
  231. WizLinks diawiz3;
  232. */
  233. //
  234. CMainTab* maintab=NULL;
  235. CShellApp* CShellApp_app=NULL;
  236.  
  237. #include "infoend.h"
  238. extern Cinfoend* this_Cinfoend;
  239.  
  240.  
  241. // PATCH-->
  242. Cinprogress* inprogress=NULL;
  243.  
  244. // nbre de slides
  245. t_StatsBuffer StatsBuffer[NStatsBuffer];
  246. void* StatsBufferback=NULL;
  247. int StatsBufferback_max=0;
  248. InpInfo SInfo;
  249.  
  250. #if USE_RAS
  251. // Chargement des librairies RAS
  252. CDynamicRAS* LibRas=NULL;
  253. int LibRasUse=0;
  254. //
  255. int connected=0;
  256. int disconnect=0;
  257. int shutdown_pc=0;
  258. HRASCONN conn = NULL;
  259. int has_started=0;
  260. char connected_err[1000]="";
  261. #endif
  262.  
  263. // pour message final
  264. extern char end_mirror_msg[8192];
  265. #include "winhttrack.h"
  266. extern CWinHTTrackApp* this_app;
  267.  
  268.  
  269. // PATCH-->
  270. // PATCH-->
  271. // FIN PATCH
  272.  
  273.  
  274. /////////////////////////////////////////////////////////////////////////////
  275. // CShellApp
  276.  
  277. /*
  278. BEGIN_MESSAGE_MAP(CShellApp, CWinApp)
  279. //{{AFX_MSG_MAP(CShellApp)
  280. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  281. // NOTE - the ClassWizard will add and remove mapping macros here.
  282. //    DO NOT EDIT what you see in these blocks of generated code!
  283. //}}AFX_MSG_MAP
  284. // Standard file based document commands
  285. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  286. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  287. // Standard print setup command
  288. ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  289. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  290. END_MESSAGE_MAP()
  291. */
  292.  
  293. /////////////////////////////////////////////////////////////////////////////
  294. // CShellApp construction
  295.  
  296. CShellApp::CShellApp()
  297. {
  298.   // TODO: add construction code here,
  299.   // Place all significant initialization in InitInstance
  300. }
  301.  
  302. /////////////////////////////////////////////////////////////////////////////
  303. // The one and only CShellApp object
  304.  
  305. //CShellApp theApp;
  306.  
  307. /////////////////////////////////////////////////////////////////////////////
  308. // CShellApp initialization
  309.  
  310. UINT RunBackMirror( LPVOID pP ) {
  311.   CShellApp_app->init_lance();
  312.   return 0;
  313. }
  314.  
  315. BOOL LaunchMirror() {
  316.   WHTT_LOCK();
  317.   hts_resetvar();
  318.   WHTT_UNLOCK();
  319.   AfxBeginThread(RunBackMirror,NULL);
  320.   return 0;
  321. }
  322.  
  323. #if 0
  324. BOOL CShellApp::InitInstance()
  325. {
  326.   CShellApp_app=this;
  327.   termine=termine_requested=shell_terminated=soft_term_requested=0;
  328.   
  329.   // Initialize OLE libraries
  330.   /*
  331.   if (!AfxOleInit())
  332.   {
  333.   AfxMessageBox(LANG(LANG_F1));
  334.   return FALSE;
  335.   }
  336.   AfxEnableControlContainer();
  337.   */
  338.   
  339.   // Fixer localisation dans la base de registre
  340.   //SetRegistryKey("WinHTTrack");
  341.   
  342.   // Standard initialization
  343.   // If you are not using these features and wish to reduce the size
  344.   //  of your final executable, you should remove from the following
  345.   //  the specific initialization routines you do not need.
  346.   /*
  347.   #ifdef _AFXDLL
  348.   Enable3dControls();            // Call this when using MFC in a shared DLL
  349.   #else
  350.   Enable3dControlsStatic();    // Call this when linking to MFC statically
  351.   #endif
  352.   */
  353.   
  354.   // Register the application's document templates.  Document templates
  355.   //  serve as the connection between documents, frame windows and views.
  356.   
  357.   // Change the registry key under which our settings are stored.
  358.   // You should modify this string to be something appropriate
  359.   // such as the name of your company or organization.
  360.   //SetRegistryKey(_T("Local AppWizard-Generated Applications"));
  361.   
  362.   //LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  363.   
  364.   // Register the application's document templates.  Document templates
  365.   //  serve as the connection between documents, frame windows and views.
  366.   
  367.   // Parse command line for standard shell commands, DDE, file open
  368.   /*CCommandLineInfo cmdInfo;
  369.   ParseCommandLine(cmdInfo);
  370.   */
  371.   
  372.   _Cinprogress_inst=NULL;
  373.   
  374.   LibRasUse=0;
  375.   
  376.   /*
  377.   #if USE_RAS
  378.   LibRas=new CDynamicRAS();
  379.   if (LibRas->IsRASLoaded()) 
  380.   LibRasUse=1;
  381.   else
  382.   LibRasUse=0;
  383.   #endif
  384.   */
  385.   
  386.   maintab = new CMainTab("WinHTTrack Website Copier");
  387.   
  388.   // PATCH-->
  389.   // ΘxΘcution..
  390.   init_lance();
  391.   
  392.   delete maintab;
  393.   maintab=NULL;
  394.   
  395.   // PATCH-->
  396.   /*
  397.   // Dispatch commands specified on the command line
  398.   if (!ProcessShellCommand(cmdInfo))
  399.         return FALSE;
  400.     
  401.       // The one and only window has been initialized, so show and update it.
  402.       m_pMainWnd->ShowWindow(SW_SHOW);
  403.       m_pMainWnd->UpdateWindow();
  404.   */  
  405.   
  406.   
  407.   return TRUE;
  408. }
  409. #endif
  410.  
  411. // PATCH-->
  412. // routines diverses
  413.  
  414. char* _SN(LLint n) {
  415.   static char str[256];
  416.   str[0]='\0';
  417.   sprintf(str,LLintP,(LLint)n);        /* 64-bit */
  418.   return str;
  419. }
  420.  
  421. // t existe-t-il comme rΘpertoire?
  422. int dir_check(char* t) {
  423.   int dir;
  424.   FILE* fp=fopen(t,"rb");
  425.   dir=(errno==13);  // is directory
  426.   if (fp) fclose(fp);
  427.   return dir;
  428. }
  429.  
  430. void check_temp(char* t,char* s) {
  431.   if (strlen(s)==0)
  432.     if (dir_check(t))
  433.       strcpybuff(s,t);
  434. }
  435.  
  436.  
  437.  
  438. // PATCH-->
  439. // Routines gestion dials
  440. // PatchΘ pour 100% dials
  441.  
  442.  
  443. void CShellApp::init_lance() {
  444.   hts_init();
  445.   htswrap_add("check-link",httrackengine_check);
  446.   htswrap_add("init",httrackengine_init);
  447.   htswrap_add("free",httrackengine_uninit);
  448.   htswrap_add("start",httrackengine_start);
  449.   htswrap_add("end",httrackengine_end);
  450.   htswrap_add("check-html",httrackengine_htmlcheck);
  451.   htswrap_add("change-options",httrackengine_chopt);
  452.   htswrap_add("loop",httrackengine_loop);
  453.   htswrap_add("query",httrackengine_query);
  454.   htswrap_add("query2",httrackengine_query2);
  455.   htswrap_add("query3",httrackengine_query3);
  456.   htswrap_add("pause",httrackengine_pause);
  457.   
  458.   termine=termine_requested=shell_terminated=soft_term_requested=0;
  459.   lance();             // Lancer miroir!
  460.   if (fp_debug) {
  461.     fprintf(fp_debug,"Building top index\r\n");
  462.     fflush(fp_debug);
  463.   }
  464.   Build_TopIndex();
  465. }
  466.  
  467. /* sauver profile */
  468. /* ask: demande confirmation, si cela vaut le coup */
  469. int Save_current_profile(int ask) {
  470.   CString winprofile;
  471.   if (ask) {
  472.     if ((dialog0->GetName().IsEmpty()) && (dialog1->m_urls.IsEmpty()))
  473.       return IDNO;
  474.     int r;
  475.     char msg[256];
  476.     sprintf(msg,"%s?\r\n%s",LANG_SAVEPROJECT,dialog0->GetName());
  477.     if ((r=AfxMessageBox(msg,MB_YESNOCANCEL)) != IDYES)
  478.       return r;
  479.   }
  480.   //
  481.   CWaitCursor wait;
  482.   
  483.   // sauver whtt
  484.   {
  485.     CString st=dialog0->GetBasePath()+dialog0->GetName()+".whtt";
  486.     FILE* fp=fopen(st,"wb");
  487.     if (fp) fclose(fp);
  488.   }
  489.   
  490.   // sauver ini
  491.   winprofile=dialog0->GetPath();
  492.   if (winprofile.GetLength()>0)
  493.     if ((winprofile.Right(1)!="/") && (winprofile.Right(1)!="\\"))
  494.       winprofile+="\\";
  495.     winprofile+="hts-cache\\";
  496.     {
  497.       char tempo[HTS_URLMAXSIZE*2];
  498.       int i;
  499.       strcpybuff(tempo,winprofile);
  500.       for(i=0;i<(int)strlen(tempo);i++)
  501.         if (tempo[i]=='\\')
  502.           tempo[i]='/';              
  503.         structcheck(tempo);
  504.     }
  505.     
  506.     winprofile+="winprofile.ini";
  507.     Write_profile(winprofile,0);
  508.     
  509.     // marquer document comme "sauvΘ"
  510.     if (this_CSplitterFrame)
  511.       this_CSplitterFrame->SetSaved();
  512.     
  513.     return IDYES;
  514. }
  515.  
  516. // reprise possible?
  517. int check_continue(char* pathlog) {
  518.   char path_log[256];
  519.   strcpybuff(path_log,pathlog);
  520.   if (strlen(path_log)>0)
  521.     if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  522.       strcatbuff(path_log,"/");
  523.     if ((fexist(fconcat(path_log,"hts-cache/new.dat"))) && (fexist(fconcat(path_log,"hts-cache/new.ndx")))) {  // il existe dΘja un cache prΘcΘdent.. renommer
  524.       //if (fexist(fconcat(path_log,"hts-cache/doit.log"))) {    // un cache est prΘsent
  525.       return 1;
  526.       //}
  527.     }
  528.     if ((fexist(fconcat(path_log,"hts-cache/old.dat"))) && (fexist(fconcat(path_log,"hts-cache/old.ndx")))) {  // il existe dΘja un ancien cache prΘcΘdent.. renommer
  529.       return 1;
  530.     }
  531.     AfxMessageBox(LANG(LANG_F2 /*"There is no cache in the directory indicated\nWinHTTrack can not find any interrupted mirror!"*/),MB_OK+MB_ICONSTOP);
  532.     return 0;
  533. }
  534.  
  535.  
  536. void CShellApp::OptPannel() {
  537.   Write_profile("<mem>",0);       // enregistrer profile dans buffer local
  538.   if (maintab->DoModal()==IDCANCEL) {
  539.     Read_profile("<mem>",0);      // restaurer
  540.   }
  541. }
  542.  
  543.  
  544. #define ADD_MIME_IN_COPT(A) \
  545.   if(strlen(maintab->m_option11.m_ext##A)+strlen(maintab->m_option11.m_mime##A)) { \
  546.   strcatbuff(buff_MIME,"--assume "); \
  547.   strcatbuff(buff_MIME,maintab->m_option11.m_ext##A); \
  548.   strcatbuff(buff_MIME,"="); \
  549.   strcatbuff(buff_MIME,maintab->m_option11.m_mime##A); \
  550.   strcatbuff(buff_MIME," "); \
  551.   } \
  552.   
  553. // parser maintab et calculer options
  554. void compute_options() { 
  555.   CWaitCursor wait;
  556.   
  557.   /* Effacer options */
  558.   LINE[0]
  559.     =OPTIONurl[0]
  560.     =OPTIONfilelist[0]
  561.     =OPTIONproxy[0]
  562.     =OPTIONproxyftp[0]
  563.     =OPTIONport[0]
  564.     =OPTIONdepth[0]
  565.     =OPTIONextdepth[0]
  566.     =OPTIONget[0]
  567.     =OPTIONwhere[0]
  568.     =OPTIONmeth[0]
  569.     =OPTIONmaxfile[0]
  570.     =OPTIONmax[0]
  571.     =OPTIONfrag[0]
  572.     =OPTIONconn[0]
  573.     =OPTIONtog[0]
  574.     =OPTIONcache[0]
  575.     =OPTIONrobots[0]
  576.     =choixdeb[0]
  577.     =build[0]
  578.     =filtre[0]
  579.     =OPTIONindex[0]
  580.     =OPTIONindex2[0]
  581.     =OPTIONdos[0]
  582.     =OPTIONtime[0]
  583.     =OPTIONrate[0]
  584.     =OPTIONhostquit[0]
  585.     =OPTIONka[0]
  586.     =OPTIONuser[0]
  587.     =OPTIONfooter[0]
  588.     =OPTIONlog[0]
  589.     =OPTIONtestall[0]
  590.     =OPTIONparseall[0]
  591.     =OPTIONlink[0]
  592.     =OPTIONpath[0]
  593.     =OPTIONretry[0]
  594.     =OPTIONerrpage[0]
  595.     =OPTIONexternal[0]
  596.     =OPTIONnopurge[0]
  597.     =OPTIONhidepwd[0]
  598.     =OPTIONhidequery[0]
  599.     =OPTIONcookies[0]
  600.     =OPTIONchecktype[0]
  601.     =OPTIONparsejava[0]
  602.     =OPTIONCache2[0]
  603.     =OPTIONlogtype[0]
  604.     =OPTIONnorecatch[0]
  605.     =OPTIONtoler[0]
  606.     =OPTIONupdhack[0]
  607.     =OPTIONhttp10[0]
  608.     =OPTIONwaittime[0]
  609.     =OPTIONmaxtime[0]
  610.     =OPTIONmaxrate[0]
  611.     =OPTIONmaxconn[0]
  612.     =OPTIONmaxlinks[0]
  613.     =OPTIONhh[0]
  614.     =OPTIONmm[0]
  615.     =OPTIONss[0]
  616.     =buff_filtres[0]
  617.     =buff_MIME[0]
  618.     =OPTION_RasString[0]
  619.     ='\0';
  620.   /* Effacer options */
  621.   
  622.   // Mode de miroir
  623.   switch(dialog1->m_todo) {
  624.   case CB_ERR: case 0:
  625.     strcpybuff(choixdeb,"w");
  626.     break;
  627.   case 1:
  628.     strcpybuff(choixdeb,"W");
  629.     break;
  630.   case 2:
  631.     strcpybuff(choixdeb,"g");
  632.     break;
  633.   case 3:
  634.     strcpybuff(choixdeb,"Y");
  635.     break;
  636.   case 4:
  637.     strcpybuff(choixdeb,"!");
  638.     break;
  639.   default:
  640.     if (dialog1->m_todo==dialog1->LAST_ACTION)
  641.       strcpybuff(choixdeb,"i");    // reprise
  642.     else
  643.       strcpybuff(choixdeb,"/");    // reprise cache prioritaire
  644.     break;
  645.   }
  646.   
  647.   // URLS
  648.   char trans[50000];
  649.   strcpybuff(trans,"");
  650.   strncatbuff(trans,dialog1->m_urls,30000);
  651.   strcpybuff(OPTIONurl,connversion(trans));
  652.   // --- formation du path
  653.   strcpybuff(OPTIONpath,"\""); strcatbuff(OPTIONpath,dialog0->GetPath0()); strcatbuff(OPTIONpath,"\"");
  654.   strcatbuff(OPTIONpath,",");
  655.   strcatbuff(OPTIONpath,"\""); strcatbuff(OPTIONpath,dialog0->GetPath0()); strcatbuff(OPTIONpath,"\"");
  656.   
  657.   // filelist
  658.   {
  659.     CString st=dialog1->m_filelist;
  660.     st.TrimLeft();
  661.     st.TrimRight();
  662.     strcpybuff(OPTIONfilelist,st);
  663.   }
  664.   
  665.   // stocker Θtat et hh/mm/ss
  666.   strcpybuff(OPTIONhh,dialog2->m_hh);
  667.   strcpybuff(OPTIONmm,dialog2->m_mm);
  668.   strcpybuff(OPTIONss,dialog2->m_ss);
  669.   if (strlen(OPTIONhh)) {    // heure
  670.     int x,y,z;
  671.     sscanf(OPTIONhh,"%d",&x);
  672.     x=min(max(x,0),23);
  673.     sprintf(OPTIONhh,"%d",x);
  674.     //
  675.     sscanf(OPTIONmm,"%d",&y);
  676.     y=min(max(y,0),59);
  677.     sprintf(OPTIONmm,"%d",y);
  678.     //
  679.     sscanf(OPTIONss,"%d",&z);
  680.     z=min(max(z,0),59);
  681.     sprintf(OPTIONss,"%d",z);
  682.     //
  683.     strcpybuff(OPTIONwaittime,"");
  684.     {
  685.       char str[32];
  686.       strcpybuff(OPTIONwaittime,"#u");
  687.       sprintf(str,"%d",x*3600+y*60+z);
  688.       strcatbuff(OPTIONwaittime,str);
  689.     }
  690.   }
  691.   strcpybuff(OPTION_RasString,dialog2->RasString);
  692.   OPTION_dial=dialog2->dial;
  693.   
  694.   if (choixdeb[0]=='/') {
  695.     strcpybuff(OPTIONcache,"C1");      // cache prio
  696.   } else {
  697.     if(!maintab->m_option3.m_cache) 
  698.       strcpybuff(OPTIONcache,"C0"); 
  699.     else 
  700.       strcpybuff(OPTIONcache,"C2");     // cache non prio 
  701.     //OPTIONcache[0]='\0'; 
  702.   }
  703.   
  704.   // ne pas recharger fichiers dΘja pris mais effacΘs
  705.   if(maintab->m_option9.m_norecatch) strcpybuff(OPTIONnorecatch,"%n"); else strcpybuff(OPTIONnorecatch,"");
  706.   
  707.   // proxy
  708.   strcpybuff(OPTIONproxy,maintab->m_option10.m_proxy);
  709.   strcpybuff(OPTIONport,maintab->m_option10.m_port);
  710.   if (maintab->m_option10.m_ftpprox) 
  711.     strcpybuff(OPTIONproxyftp, "%f");
  712.   else
  713.     strcpybuff(OPTIONproxyftp, "%f0");   
  714.   
  715.   //depth
  716.   strcpybuff(OPTIONdepth,maintab->m_option5.m_depth);
  717.   strcpybuff(OPTIONextdepth,maintab->m_option5.m_depth2);
  718.   
  719.   if(!maintab->m_option9.m_index) strcpybuff(OPTIONindex,"I0"); else OPTIONindex[0]='\0'; 
  720.   if(!maintab->m_option9.m_index2) strcpybuff(OPTIONindex2,"%I0"); else strcpybuff(OPTIONindex2,"%I"); 
  721.   if(maintab->m_option2.m_dos) 
  722.     strcpybuff(OPTIONdos,"L0"); 
  723.   else if(maintab->m_option2.m_iso9660) 
  724.     strcpybuff(OPTIONdos,"L2"); 
  725.   else 
  726.     OPTIONdos[0]='\0'; 
  727.   if(maintab->m_option1.m_testall) strcpybuff(OPTIONtestall,"t"); else OPTIONtestall[0]='\0'; 
  728.   if(maintab->m_option1.m_parseall) strcpybuff(OPTIONparseall,"%P"); else strcpybuff(OPTIONparseall,"%P0"); 
  729.   if(maintab->m_option1.m_link) strcpybuff(OPTIONlink,"n"); else OPTIONlink[0]='\0'; 
  730.   if(maintab->m_option1.m_htmlfirst) strcpybuff(OPTIONhtmlfirst,"p7"); else strcpybuff(OPTIONhtmlfirst,""); 
  731.   if(maintab->m_option2.m_errpage) strcpybuff(OPTIONerrpage,"o0"); else OPTIONerrpage[0]='\0'; 
  732.   if(maintab->m_option2.m_external) strcpybuff(OPTIONexternal,"x"); else OPTIONexternal[0]='\0'; 
  733.   if(maintab->m_option2.m_nopurge) strcpybuff(OPTIONnopurge,"X0"); else OPTIONnopurge[0]='\0'; 
  734.   if(maintab->m_option2.m_hidepwd) strcpybuff(OPTIONhidepwd,"%x"); else OPTIONhidepwd[0]='\0'; 
  735.   if(maintab->m_option2.m_hidequery) strcpybuff(OPTIONhidequery,"%q0"); else OPTIONhidequery[0]='\0'; 
  736.   
  737.   OPTIONrobots[0]='\0';
  738.   if(maintab->m_option8.m_robots==0) strcpybuff(OPTIONrobots,"s0"); 
  739.   else if(maintab->m_option8.m_robots==1) strcpybuff(OPTIONrobots,"s1"); 
  740.   else if(maintab->m_option8.m_robots==2) strcpybuff(OPTIONrobots,"s2"); 
  741.   
  742.   // cookies,checktype,parsejava
  743.   if(maintab->m_option8.m_cookies==0) strcpybuff(OPTIONcookies,"b0"); // else strcpybuff(OPTIONcookies,"b1");
  744.   if (maintab->m_option8.m_checktype>=0)
  745.     sprintf(OPTIONchecktype,"u%d",maintab->m_option8.m_checktype);
  746.   if(maintab->m_option8.m_parsejava==0) strcpybuff(OPTIONparsejava,"j0"); // else strcpybuff(OPTIONcookies,"j1");
  747.   if (maintab->m_option8.m_http10) strcpybuff(OPTIONhttp10,"%h");   // HTTP/1.0 notamment
  748.   if (maintab->m_option8.m_toler)  strcpybuff(OPTIONtoler,"%B");    // tolerent
  749.   if (maintab->m_option8.m_updhack)  strcpybuff(OPTIONupdhack,"%s");    // update hack
  750.   
  751.   // store all in cache,logtype
  752.   if(maintab->m_option9.m_Cache2!=0) strcpybuff(OPTIONCache2,"k");
  753.   if(maintab->m_option9.m_logtype==1) strcpybuff(OPTIONlogtype,"z");
  754.   else if(maintab->m_option9.m_logtype==2) strcpybuff(OPTIONlogtype,"Z");
  755.   if (maintab->m_option3.m_windebug) strcatbuff(OPTIONlogtype,"%H");      // debug headers
  756.   
  757.   strcpybuff(build,"");
  758.   if      (maintab->m_option2.m_build==0) strcpybuff(build,"N0");
  759.   else if (maintab->m_option2.m_build==1) strcpybuff(build,"N1");
  760.   else if (maintab->m_option2.m_build==2) strcpybuff(build,"N2");
  761.   else if (maintab->m_option2.m_build==3) strcpybuff(build,"N3");
  762.   else if (maintab->m_option2.m_build==4) strcpybuff(build,"N4");
  763.   else if (maintab->m_option2.m_build==5) strcpybuff(build,"N5");
  764.   else if (maintab->m_option2.m_build==6) strcpybuff(build,"N100");
  765.   else if (maintab->m_option2.m_build==7) strcpybuff(build,"N101");
  766.   else if (maintab->m_option2.m_build==8) strcpybuff(build,"N102");
  767.   else if (maintab->m_option2.m_build==9) strcpybuff(build,"N103");
  768.   else if (maintab->m_option2.m_build==10) strcpybuff(build,"N104");
  769.   else if (maintab->m_option2.m_build==11) strcpybuff(build,"N105");
  770.   else if (maintab->m_option2.m_build==12) strcpybuff(build,"N99");
  771.   else if (maintab->m_option2.m_build==13) strcpybuff(build,"N199");
  772.   else if (maintab->m_option2.m_build==14) {
  773.     strcpybuff(build,"-N \"");
  774.     strcatbuff(build,maintab->m_option2.Bopt.m_BuildString);
  775.     strcatbuff(build,"\"");
  776.   }
  777.   
  778.   strcpybuff(filtre,"");
  779.   if      (maintab->m_option3.m_filter==0) strcpybuff(filtre,"p0");
  780.   else if (maintab->m_option3.m_filter==1) strcpybuff(filtre,"p1");
  781.   else if (maintab->m_option3.m_filter==2) strcpybuff(filtre,"p2");
  782.   else if (maintab->m_option3.m_filter==3) {    /* default */
  783.     if(!maintab->m_option1.m_htmlfirst) strcpybuff(filtre,"p3");
  784.   }
  785.   else if (maintab->m_option3.m_filter==4) strcpybuff(filtre,"p7");
  786.   //
  787.   if      (maintab->m_option3.m_travel==0) strcatbuff(filtre,"S");
  788.   else if (maintab->m_option3.m_travel==1) strcatbuff(filtre,"D");
  789.   else if (maintab->m_option3.m_travel==2) strcatbuff(filtre,"U");
  790.   else if (maintab->m_option3.m_travel==3) strcatbuff(filtre,"B");
  791.   //
  792.   if      (maintab->m_option3.m_travel2==0) strcatbuff(filtre,"a");
  793.   else if (maintab->m_option3.m_travel2==1) strcatbuff(filtre,"d");
  794.   else if (maintab->m_option3.m_travel2==2) strcatbuff(filtre,"l");
  795.   else if (maintab->m_option3.m_travel2==3) strcatbuff(filtre,"e");
  796.   //
  797.   if      (maintab->m_option3.m_travel3==0) strcatbuff(filtre,"K0");
  798.   else if (maintab->m_option3.m_travel3==1) strcatbuff(filtre,"K");
  799.   else if (maintab->m_option3.m_travel3==2) strcatbuff(filtre,"K3");
  800.   else if (maintab->m_option3.m_travel3==3) strcatbuff(filtre,"K4");
  801.  
  802.   if (maintab->m_option9.m_logf) strcpybuff(OPTIONlog,"f2"); else strcpybuff(OPTIONlog,"Q"); 
  803.   
  804.   if(maintab->m_option5.m_sizemax!=""){
  805.     strcpybuff(OPTIONmax,"M");
  806.     strcatbuff(OPTIONmax,maintab->m_option5.m_sizemax);
  807.   } else strcpybuff(OPTIONmax,"");
  808.   
  809.   if(maintab->m_option5.m_pausebytes!=""){
  810.     strcpybuff(OPTIONfrag,"G");
  811.     strcatbuff(OPTIONfrag,maintab->m_option5.m_pausebytes);
  812.   } else strcpybuff(OPTIONfrag,"");
  813.   
  814.   
  815.   if(maintab->m_option5.m_maxhtml!="" || maintab->m_option5.m_othermax!="" ){
  816.     strcpybuff(OPTIONmaxfile,"m");
  817.     if(maintab->m_option5.m_othermax!="") strcatbuff(OPTIONmaxfile,maintab->m_option5.m_othermax);
  818.     else strcatbuff(OPTIONmaxfile,"0");
  819.     if(maintab->m_option5.m_maxhtml!="") {strcatbuff(OPTIONmaxfile,",");strcatbuff(OPTIONmaxfile,maintab->m_option5.m_maxhtml);}
  820.     else {strcatbuff(OPTIONmaxfile,",");strcatbuff(OPTIONmaxfile,"0");}
  821.   } else strcpybuff(OPTIONmaxfile,"");
  822.   
  823.   if(strcmp(maintab->m_option4.m_connexion,"")!=0){
  824.     strcpybuff(OPTIONconn,"c");
  825.     strcatbuff(OPTIONconn,maintab->m_option4.m_connexion);
  826.   } else strcpybuff(OPTIONconn,"");
  827.   
  828.   if(strcmp(maintab->m_option4.m_timeout,"")!=0){
  829.     strcpybuff(OPTIONtime,"T");
  830.     strcatbuff(OPTIONtime,maintab->m_option4.m_timeout);
  831.   } else strcpybuff(OPTIONtime,"");
  832.   
  833.   // quitter host si timeout ou rate out
  834.   strcpybuff(OPTIONhostquit,"");
  835.   {
  836.     int a=0;
  837.     if (maintab->m_option4.m_remt)
  838.       a+=1;
  839.     if (maintab->m_option4.m_rems)
  840.       a+=2;
  841.     sprintf(OPTIONhostquit,"H%d",a);
  842.   }
  843.  
  844.   // Keep-Alive
  845.   if (maintab->m_option4.m_ka) {
  846.     strcpybuff(OPTIONka, "%k");
  847.   } else {
  848.     strcpybuff(OPTIONka, "%k0");
  849.   }
  850.  
  851.   
  852.   //--> max time
  853.   if(strcmp(maintab->m_option5.m_maxtime,"")!=0){
  854.     strcpybuff(OPTIONmaxtime,"E");
  855.     strcatbuff(OPTIONmaxtime,maintab->m_option5.m_maxtime);
  856.   } else strcpybuff(OPTIONmaxtime,"");
  857.   
  858.   //--> max rate
  859.   if(strcmp(maintab->m_option5.m_maxrate,"")!=0){
  860.     strcpybuff(OPTIONmaxrate,"A");
  861.     strcatbuff(OPTIONmaxrate,maintab->m_option5.m_maxrate);
  862.   } else strcpybuff(OPTIONmaxrate,"");
  863.   
  864.   if(strcmp(maintab->m_option5.m_maxconn,"")!=0){
  865.     strcpybuff(OPTIONmaxconn,"%c");
  866.     strcatbuff(OPTIONmaxconn,maintab->m_option5.m_maxconn);
  867.   } else strcpybuff(OPTIONmaxconn,"");
  868.   
  869.   if(strcmp(maintab->m_option5.m_maxlinks,"")!=0){
  870.     strcpybuff(OPTIONmaxlinks,"#L");
  871.     strcatbuff(OPTIONmaxlinks,maintab->m_option5.m_maxlinks);
  872.   } else strcpybuff(OPTIONmaxlinks,"");
  873.   
  874.   if(strcmp(maintab->m_option4.m_rate,"")!=0){
  875.     strcpybuff(OPTIONrate,"J");
  876.     strcatbuff(OPTIONrate,maintab->m_option4.m_rate);
  877.   } else strcpybuff(OPTIONrate,"");
  878.   
  879.   if(strcmp(maintab->m_option6.m_user,"")!=0){
  880.     strcpybuff(OPTIONuser,"\"");
  881.     strcatbuff(OPTIONuser,maintab->m_option6.m_user);
  882.     strcatbuff(OPTIONuser,"\"");
  883.   } else strcpybuff(OPTIONuser,"");
  884.   
  885.   if(strcmp(maintab->m_option6.m_footer,"")!=0){
  886.     strcpybuff(OPTIONfooter,"\"");
  887.     strcatbuff(OPTIONfooter,maintab->m_option6.m_footer);
  888.     strcatbuff(OPTIONfooter,"\"");
  889.   } else strcpybuff(OPTIONfooter,"");
  890.   
  891.   if(strcmp(maintab->m_option4.m_retry,"")!=0){
  892.     strcpybuff(OPTIONretry,"R");
  893.     strcatbuff(OPTIONretry,maintab->m_option4.m_retry);
  894.   } else strcpybuff(OPTIONretry,"");
  895.   
  896.   if(strcmp(maintab->m_option7.m_url2,"")!=0){
  897.     strcpybuff(buff_filtres,maintab->m_option7.m_url2);
  898.   } else strcpybuff(buff_filtres,"");
  899.   
  900.   
  901.   // MIME
  902.   buff_MIME[0]='\0';
  903.   ADD_MIME_IN_COPT(1)
  904.     ADD_MIME_IN_COPT(2)
  905.     ADD_MIME_IN_COPT(3)
  906.     ADD_MIME_IN_COPT(4)
  907.     ADD_MIME_IN_COPT(5)
  908.     ADD_MIME_IN_COPT(6)
  909.     ADD_MIME_IN_COPT(7)
  910.     ADD_MIME_IN_COPT(8)
  911.     
  912.     /* autres options: RAS */
  913.     if (dialog2->m_rasdisc)
  914.       disconnect=1;     /* dΘconnexion α la fin */
  915.     else
  916.       disconnect=0;
  917.  
  918.     /* autres options: Shutdown */
  919.     if (dialog2->m_rasshut)
  920.       shutdown_pc=1;     /* Θtendre α la fin */
  921.     else
  922.       shutdown_pc=0;
  923. }
  924.  
  925. // Les routines α dΘfinir:
  926. int __cdecl httrackengine_check(char* adr,char* fil,int status) {  // appelΘ par le wizard
  927.   return -1;
  928. }
  929. void __cdecl httrackengine_init() {    // appelΘ lors de l'init de HTTRACK, avant le dΘbut d'un miroir
  930. #if USE_RAS
  931.   has_started=0;
  932. #endif
  933.   httrackengine_loop(NULL,0,0,0,0,NULL,0);  // init
  934.   //printf("DEMARRAGE DU MIROIR DETECTE\n");  
  935. }
  936. void __cdecl httrackengine_uninit() {  // appelΘ en fin de miroir (peut Ωtre utile!!!)
  937. #if USE_RAS
  938.   if (LibRasUse) {        /* librairie RAS chargΘe */
  939.     if (disconnect) {     /* on doit dΘconnecter */
  940.       if (connected) {    /* on a initiΘ une connexion */
  941.         if (conn)
  942.           LibRas->RasHangUp(conn);
  943.       } else {            /* tout dΘconnecter */
  944.         // On coupe tout (non, pas bourrin)
  945.         DWORD size;
  946.         RASCONN* adr;
  947.         int count=256;
  948.         size = sizeof(RASCONN)*(count+2);
  949.         adr = (RASCONN*) (char*) calloc(size,1);
  950.         if (adr) {
  951.           DWORD ent;
  952.           int i;
  953.           for(i=0;i<count;i++) {
  954.             adr[i].dwSize=sizeof(RASCONN);
  955.             strcpybuff(adr[i].szEntryName,"");
  956.           }
  957.           if (LibRas->RasEnumConnections((RASCONN*) adr,&size,&ent) == 0) {
  958.             for(i=0;i<(int)ent;i++) {
  959.               LibRas->RasHangUp(adr[i].hrasconn);
  960.             }
  961.           }
  962.           free(adr);
  963.         }
  964.         
  965.       }
  966.     }
  967.     if (shutdown_pc) {
  968.       ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF /*| EWX_FORCEIFHUNG*/, 0);
  969.     }
  970.   }
  971. #endif
  972. }
  973. int __cdecl httrackengine_start(void* dummy) {   // appelΘ lors du dΘmarrage du miroir (premiΦres requΦtes)
  974. #if USE_RAS
  975.   // connexion RAS
  976.   has_started=1;    // dΘmarrage
  977.   connected=0;
  978.   conn = NULL;
  979.   memset(&SInfo, 0, sizeof(SInfo));
  980.   if (LibRasUse) {
  981.     if (strlen(OPTION_RasString)>0) {    // sΘlection provider
  982.       if (!LibRas->RasDial(NULL,NULL,&OPTION_dial,NULL,NULL,&conn)) {
  983.         RASCONNSTATUS status;
  984.         do {
  985.           status.dwSize = sizeof(status);
  986.           LibRas->RasGetConnectStatus(conn,&status);
  987.           switch(status.rasconnstate) {
  988.           case RASCS_Connected : 
  989.             connected=1;
  990.             break;
  991.           case RASCS_Disconnected :
  992.             strcpybuff(connected_err,LANG(LANG_F3 /*"Could not connect to provider"*/));
  993.             connected=-1;
  994.             break;
  995.           }
  996.         } while(connected==0);
  997.       } else {
  998.         strcpybuff(connected_err,LANG(LANG_F3 /*"Could not connect to provider","Impossible d'Θtablir la connexion"*/));
  999.         connected=-1;
  1000.         //termine=1;
  1001.       }
  1002.     }
  1003.     //
  1004.     if (connected != -1)  // si pas d'erreur RAS
  1005.       return 1;
  1006.     else
  1007.       return 0;
  1008.   } else
  1009.     return 1;
  1010. #else
  1011.   return 1;
  1012. #endif
  1013. }
  1014. int  httrackengine_end() {     // appelΘ lors de la fin du miroir (plus de liens α charger)
  1015.   WHTT_LOCK();
  1016.   termine=1;
  1017.   if (_Cinprogress_inst) {
  1018.     _Cinprogress_inst->EndDialog(IDOK);
  1019.     _Cinprogress_inst=NULL;
  1020.   }
  1021.   WHTT_UNLOCK();
  1022.   return 1;
  1023. }
  1024. int __cdecl httrackengine_htmlcheck(char* html,int len,char* url_adresse,char* url_fichier) {    // appelΘ α chaque fois qu'un html doit Ωtre scannΘ (utile pour la prospection mais inutile ici)
  1025.   return 1;
  1026. }
  1027. int __cdecl httrackengine_chopt(void* opt) {
  1028.   return 1;
  1029. }
  1030.  
  1031. // Le routine la plus utile sans doute: elle refresh les tableaux
  1032. // C'est la 2e routine en thread qui assure le refresh graphique
  1033. // (plus efficace)
  1034. // -->C'est elle qui dΘcide de tout arrΩter si elle dΘtecte in termine_request<--
  1035. int __cdecl httrackengine_loop(
  1036.                                void* _back,int back_max,int back_index,
  1037.                                int lien_n,int lien_tot,
  1038.                                int stat_time,
  1039.                                hts_stat_struct* stats) {    // appelΘ α chaque boucle de HTTrack
  1040.   static char s[HTS_URLMAXSIZE*2]="";  // utilisΘ plus loin
  1041.   int stat_written=-1;
  1042.   int stat_updated=-1;
  1043.   int stat_errors=-1;
  1044.   int stat_warnings=-1;
  1045.   int stat_infos=-1;
  1046.   int nbk=-1;
  1047.   LLint nb=-1;
  1048.   int stat_nsocket=-1;
  1049.   LLint stat_bytes=-1;
  1050.   LLint stat_bytes_recv=-1;
  1051.   int irate=-1;
  1052.   
  1053.   WHTT_LOCK();
  1054.  
  1055.   if (stats) {
  1056.     stat_written=stats->stat_files;
  1057.     stat_updated=stats->stat_updated_files;
  1058.     stat_errors=stats->stat_errors;
  1059.     stat_warnings=stats->stat_warnings;
  1060.     stat_infos=stats->stat_infos;
  1061.     nbk=stats->nbk;
  1062.     stat_nsocket=stats->stat_nsocket;
  1063.     irate=(int)stats->rate;
  1064.     nb=stats->nb;
  1065.     stat_bytes=stats->nb;
  1066.     stat_bytes_recv=stats->HTS_TOTAL_RECV;
  1067.   }
  1068.   
  1069. #if !SHELL_MULTITHREAD
  1070.   static TStamp last_time;
  1071. #endif
  1072.   int rate;
  1073.   // casts
  1074.   lien_back* back=(lien_back*) _back;
  1075.   //  static int ft=-1;
  1076.   
  1077.   if (back_max == 0) {
  1078. #if !SHELL_MULTITHREAD
  1079.     last_time=0;
  1080. #endif
  1081.     // en cas de manque de time
  1082.     SInfo.refresh=1;
  1083.     SInfo.stat_timestart=time_local();
  1084.     WHTT_UNLOCK();
  1085.     return 1;
  1086.   }
  1087.   
  1088.   if ((termine) || (termine_requested)) {
  1089.     SInfo.refresh=0;      // pas de refresh
  1090.     SInfo.refresh=0;      // pas de refresh
  1091.     termine_requested=1;
  1092.     WHTT_UNLOCK();
  1093.     return 0;
  1094.   }
  1095.   
  1096.   if (stat_written>=0) SInfo.stat_written=stat_written;
  1097.   if (stat_updated>=0) SInfo.stat_updated=stat_updated;
  1098.   if (stat_errors>=0)  SInfo.stat_errors=stat_errors;
  1099.   if (stat_warnings>=0)  SInfo.stat_warnings=stat_warnings;
  1100.   if (stat_infos>=0)  SInfo.stat_infos=stat_infos;
  1101.   
  1102. #if SHELL_MULTITHREAD 
  1103.   //if (((tl-last_time)>=100) || ((tl-last_time)<0)) {   // chaque 100 ms
  1104.   if (SInfo.ask_refresh) {
  1105. #else
  1106.     TStamp tl=0;
  1107.     {
  1108.       time_t tt;
  1109.       struct tm* A;
  1110.       tt=time(NULL);
  1111.       A=localtime(&tt);
  1112.       tl+=A->tm_sec;
  1113.       tl+=A->tm_min*60;
  1114.       tl+=A->tm_hour*60*60;
  1115.       //tl+=A->tm_yday*60*60*24;
  1116.       //tl+=A->tm_year*60*60*24*365;
  1117.       
  1118.       tl*=1000;  // en ms
  1119.       
  1120.       struct _timeb timebuffer;
  1121.       char *timeline;
  1122.       _ftime( &timebuffer );
  1123.       timeline = ctime( & ( timebuffer.time ) );
  1124.       
  1125.       tl+=timebuffer.millitm;    // + ms
  1126.     }
  1127.     if (((tl-last_time)>=HTS_SLEEP_WIN) || ((tl-last_time)<0)) {   // chaque 250 ms
  1128.       last_time=tl;
  1129. #endif
  1130.       //INFILLMEM_LOCKED=1;    // locker interface
  1131.       // OPTI int rate;
  1132.       SInfo.ask_refresh=0;
  1133.       
  1134.       // pour Θviter temps cpu consommΘ trop grand
  1135.       // Sleep(10);
  1136.       
  1137.       // initialiser ft
  1138.       if ((stat_nsocket==-1)) {
  1139.         if (SInfo.ft==-1) {
  1140.           SInfo.ft=stat_time;
  1141.         }
  1142.       }
  1143.       
  1144. #if !SHELL_MULTITHREAD
  1145.       //
  1146.       MSG msg;  
  1147.       if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE )) {     
  1148.         switch (msg.message) {
  1149.         case WM_COMMAND:        
  1150.           switch(msg.wParam) { 
  1151.           case ID_APP_ABOUT: {
  1152.             Cabout about;
  1153.             about.DoModal();                                    }
  1154.             break;
  1155.           case ID_APP_EXIT: case WM_CLOSE :
  1156.             termine_requested=1;
  1157.             break;
  1158.           case  WM_DESTROY: case WM_NCDESTROY: 
  1159.             termine_requested=1;
  1160.             break;
  1161.           }
  1162.           break;        
  1163.           default:
  1164.             DefWindowProc(msg.hwnd,msg.message,msg.wParam,msg.lParam);
  1165.             break;
  1166.         }
  1167.       }
  1168.       //
  1169. #endif
  1170.       
  1171.       // calculer heure si ce n'est dΘja fait
  1172.       if (stat_time<0)
  1173.         SInfo.stat_time=(int) (time_local()-SInfo.stat_timestart);
  1174.       
  1175.       // calculer transfer rate
  1176.       if ((stat_time>0) && (stat_bytes_recv>0))
  1177.         rate=(int)(stat_bytes_recv/stat_time);
  1178.       else
  1179.         rate=0;    // pas d'infos
  1180.       
  1181.       // stocker infos: octets transfΘrΘs, temps, etc.
  1182.       if (stat_bytes>=0) SInfo.stat_bytes=stat_bytes;      // bytes
  1183.       if (stat_time>=0) SInfo.stat_time=stat_time;         // time
  1184.       if (lien_tot>=0) SInfo.lien_tot=lien_tot; // nb liens
  1185.       if (lien_n>=0) SInfo.lien_n=lien_n;       // scanned
  1186.       SInfo.stat_nsocket=stat_nsocket;          // socks
  1187.       if (rate>0)  SInfo.rate=rate;                // rate
  1188.       if (irate>=0) SInfo.irate=irate;             // irate
  1189.       if (SInfo.irate<0) SInfo.irate=SInfo.rate;
  1190.       if (nbk>=0) SInfo.stat_back=nbk;
  1191.       
  1192.       // back: tableau de back_max ΘlΘments de cache
  1193.       // back_max: nombre d'ΘlΘments ^^^^
  1194.       // lien_tot: nombre total de liens traitΘs pour le moment
  1195.       // stat_bytes: octets sauvegardΘs
  1196.       // stat_bytes_recv: octets tΘlΘchargΘs
  1197.       // stat_time: temps en seconde depuis le dΘbut du miroir
  1198.       // stat_nsocket: nombre de sockets connectΘes actuellement
  1199.       // on peut en dΘduire rate=stat_bytes_recv/stat_time
  1200.       
  1201.       // printf("loop.. %d liens, %d octets, %d secondes, %d sockets, TAUX=%d\n",lien_tot,stat_bytes,stat_time,stat_nsocket,rate);
  1202.       
  1203.       // parcourir registre des liens
  1204.       if (back_index>=0) {  // seulement si index passΘ
  1205.         int j,k;
  1206.         int index=0;
  1207.         int ok=0;         // idem
  1208.         int l;            // idem
  1209.         int M=32;         // idem
  1210.         
  1211.         StatsBufferback=(void*) back;
  1212.         StatsBufferback_max=back_max;
  1213.         {
  1214.           int i;
  1215.           for(i=0;i<NStatsBuffer;i++) {
  1216.             strcpybuff(StatsBuffer[i].etat,"");
  1217.             strcpybuff(StatsBuffer[i].nom,"");
  1218.             strcpybuff(StatsBuffer[i].fichier,"");
  1219.             strcpybuff(StatsBuffer[i].url_sav,"");
  1220.             StatsBuffer[i].back=NULL;
  1221.             StatsBuffer[i].size=0;
  1222.             StatsBuffer[i].sizetot=0;
  1223.           }
  1224.         }
  1225.         for(k=0;k<2;k++) {    // 0: lien en cours 1: autres liens
  1226.           for(j=0;(j<3) && (index<NStatsBuffer);j++) {  // passe de prioritΘ
  1227.             int _i;
  1228.             for(_i=0+k;(_i< max(back_max*k,1) ) && (index<NStatsBuffer);_i++) {  // no lien
  1229.               int i=(back_index+_i)%back_max;    // commencer par le "premier" (l'actuel)
  1230.               if (back[i].status>=0) {     // signifie "lien actif"
  1231.                 // int ok=0;  // OPTI
  1232.                 ok=0;
  1233.                 switch(j) {
  1234.                 case 0:     // prioritaire
  1235.                   if ((back[i].status>0) && (back[i].status<99)) {
  1236.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F4 /*"receive","rΘception"*/)); ok=1;
  1237.                   }
  1238.                   break;
  1239.                 case 1:
  1240.                   if (back[i].status==99) {
  1241.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F5 /*"request","requΦte"*/)); ok=1;
  1242.                   }
  1243.                   else if (back[i].status==100) {
  1244.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F6 /*"connect","connexion"*/)); ok=1;
  1245.                   }
  1246.                   else if (back[i].status==101) {
  1247.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F7 /*"search","recherche"*/)); ok=1;
  1248.                   }
  1249.                   else if (back[i].status==1000) {    // ohh le beau ftp
  1250.                     sprintf(StatsBuffer[index].etat,"ftp: %s",back[i].info); ok=1;
  1251.                   }
  1252.                   else if (back[i].status==102) {         // SSL handshake
  1253.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F6 /*"connect","connexion"*/)); ok=1;
  1254.                   }
  1255.                   else if (back[i].status==-103) {         // waiting (keep-alive)
  1256.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F8)); ok=1;
  1257.                   }
  1258.                   break;
  1259.                 default:
  1260.                   if (back[i].status==0) {  // prΩt
  1261.                     if ((back[i].r.statuscode==200)) {
  1262.                       strcpybuff(StatsBuffer[index].etat,LANG(LANG_F8 /*"ready","prΩt"*/)); ok=1;
  1263.                     }
  1264.                     else if ((back[i].r.statuscode>=100) && (back[i].r.statuscode<=599)) {
  1265.                       char tempo[256]; tempo[0]='\0';
  1266.                       infostatuscode(tempo,back[i].r.statuscode);
  1267.                       strcpybuff(StatsBuffer[index].etat,tempo); ok=1;
  1268.                     }
  1269.                     else {
  1270.                       strcpybuff(StatsBuffer[index].etat,LANG(LANG_F9 /*"error","erreur"*/)); ok=1;
  1271.                     }
  1272.                   }
  1273.                   break;
  1274.                 }
  1275.                 
  1276.                 if (ok) {
  1277.                   // OPTI int l;
  1278.                   // OPTI int M=32;     // longueur
  1279.                   // OPTI char s[HTS_URLMAXSIZE*2]="";
  1280.                   //
  1281.                   StatsBuffer[index].back=i;        // index pour + d'infos
  1282.                   //
  1283.                   s[0]='\0';
  1284.                   strcpybuff(StatsBuffer[index].url_sav,back[i].url_sav);   // pour cancel
  1285.                   if (strcmp(back[i].url_adr,"file://"))
  1286.                     strcatbuff(s,back[i].url_adr);
  1287.                   else
  1288.                     strcatbuff(s,"localhost");
  1289.                   if (back[i].url_fil[0]!='/')
  1290.                     strcatbuff(s,"/");
  1291.                   strcatbuff(s,back[i].url_fil);
  1292.                   
  1293.                   StatsBuffer[index].fichier[0]='\0';
  1294.                   {
  1295.                     char* a=strrchr(s,'/');
  1296.                     if (a) {
  1297.                       strncatbuff(StatsBuffer[index].fichier,a,200);
  1298.                       *a='\0';
  1299.                     }
  1300.                   }
  1301.                   
  1302.                   if ((l=strlen(s))<MAX_LEN_INPROGRESS)
  1303.                     strcpybuff(StatsBuffer[index].nom,s);
  1304.                   else {
  1305.                     // couper
  1306.                     StatsBuffer[index].nom[0]='\0';
  1307.                     strncatbuff(StatsBuffer[index].nom,s,MAX_LEN_INPROGRESS/2-2);
  1308.                     strcatbuff(StatsBuffer[index].nom,"...");
  1309.                     strcatbuff(StatsBuffer[index].nom,s+l-MAX_LEN_INPROGRESS/2+2);
  1310.                   }
  1311.                   
  1312.                   //if (back[i].url_fil[0]!='/') printf("/");
  1313.                   
  1314.                   if (back[i].r.totalsize>0) {  // taille prΘdΘfinie
  1315.                     StatsBuffer[index].sizetot=back[i].r.totalsize;
  1316.                     StatsBuffer[index].size=back[i].r.size;
  1317.                   } else {  // pas de taille prΘdΘfinie
  1318.                     if (back[i].status==0) {  // prΩt
  1319.                       StatsBuffer[index].sizetot=back[i].r.size;
  1320.                       StatsBuffer[index].size=back[i].r.size;
  1321.                     } else {
  1322.                       StatsBuffer[index].sizetot=8192;
  1323.                       StatsBuffer[index].size=(back[i].r.size % 8192);
  1324.                     }
  1325.                   }
  1326.                   index++;
  1327.                 }
  1328.               }
  1329.             }
  1330.           }
  1331.         }
  1332.     }
  1333.     
  1334. #if SHELL_MULTITHREAD
  1335.     SInfo.refresh=1;     // on signale qu'il faut faire un refresh!
  1336. #else
  1337.     inprogress_refresh();  // tout de suite (non multithread)
  1338. #endif
  1339.     // INFILLMEM_LOCKED=0;    // dΘlocker interface
  1340.   }
  1341.   WHTT_UNLOCK();
  1342.   return (termine==0);
  1343. }
  1344.  
  1345. int inprogress_refresh() {
  1346.   static int toggle=0;
  1347.   // WHTT_LOCK(); // deja fait
  1348.   if ((!termine) && (!termine_requested) && (inprogress->m_hWnd)) {
  1349.     if (SInfo.refresh) {
  1350.       // INREDRAW_LOCKED=1;
  1351.       // REFRESH (si nb de socket==-1 on manage les fenetres)
  1352.       int icn;
  1353.       icn=inprogress->IsIconic();
  1354.       CString lnk;
  1355.       if (SInfo.stat_back)
  1356.         lnk.Format("%d/%d (+%d)",SInfo.lien_n,SInfo.lien_tot-1,SInfo.stat_back);
  1357.       else
  1358.         lnk.Format("%d/%d",SInfo.lien_n,SInfo.lien_tot-1);
  1359.       if (!icn) {
  1360.         int parsing=0;
  1361.         if (!soft_term_requested) {
  1362.           if (!hts_setpause(-1)) {
  1363.             if (!(parsing=hts_is_parsing(-1)))
  1364.               inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F10 /*"Receiving files.","RΘception des fichiers"*/)); 
  1365.             else {
  1366.               switch(hts_is_testing()) {
  1367.               case 0:
  1368.                 inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F11 /*"Parsing HTML file..","Parcours du fichier HTML"*/)); 
  1369.                 break;
  1370.               case 1:
  1371.                 inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F12 /*"Parsing HTML file (testing links)..","Parcours du fichier HTML (test des liens)"*/)); 
  1372.                 break;
  1373.               case 2:
  1374.                 inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F11b)); 
  1375.                 break;
  1376.               case 3:
  1377.                 inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F11c)); 
  1378.                 break;
  1379.               }
  1380.             }
  1381.           } else {
  1382.             if (((toggle++)/5)%2)
  1383.               inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F13 /*"Paused (select [File]/[Pause transfer] to continue)","Interrompu (choisir [Fichier]/[Interrompre transferts] pour continuer)"*/));
  1384.             else
  1385.               inprogress->SetDlgItemText(IDC_inforun,"");
  1386.           }
  1387.         } else {
  1388.           if (((toggle++)/5)%2)
  1389.             inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F13b));
  1390.           else
  1391.             inprogress->SetDlgItemText(IDC_inforun,"");
  1392.         }
  1393.         
  1394.         if (SInfo.stat_time>0) {
  1395.           char s[256];
  1396.           qsec2str(s,(TStamp) SInfo.stat_time);
  1397.           inprogress->SetDlgItemText(IDC_i1 ,s);  // time
  1398.         } else
  1399.           inprogress->SetDlgItemText(IDC_i1 , _SN(SInfo.stat_time) );  // time
  1400.         inprogress->SetDlgItemText(IDC_i0 , int2bytes(SInfo.stat_bytes) );  // bytes
  1401.         inprogress->SetDlgItemText(IDC_i2 , lnk);  // scanned
  1402.         if (SInfo.stat_nsocket>0)
  1403.           inprogress->SetDlgItemText(IDC_i3 , _SN(SInfo.stat_nsocket) );  // socks
  1404.         else
  1405.           inprogress->SetDlgItemText(IDC_i3 , "none" );  // wait
  1406.         
  1407.         CString st;
  1408.         st.Format("%s (%s)",int2bytessec(SInfo.irate),int2bytessec(SInfo.rate));
  1409.         inprogress->SetDlgItemText(IDC_i4 , st );  // rate
  1410.         
  1411.         inprogress->SetDlgItemText(IDC_i5 , _SN(SInfo.stat_errors) );
  1412.         inprogress->SetDlgItemText(IDC_i6 , _SN(SInfo.stat_written) );
  1413.         {
  1414.           char tempo[256];
  1415.           int pc=0;
  1416.           if (SInfo.stat_written)
  1417.             pc=(int)((SInfo.stat_updated*100)/(SInfo.stat_written));
  1418.           if (pc)
  1419.             sprintf(tempo,"%d (%d%%)",SInfo.stat_updated,pc);
  1420.           else
  1421.             sprintf(tempo,"%d",SInfo.stat_updated);
  1422.           inprogress->SetDlgItemText(IDC_i7 , tempo );
  1423.         }
  1424.         
  1425.         /*if (!parsing)*/
  1426.         {
  1427.           {
  1428.             int i;
  1429.             for(i=0;i<NStatsBuffer;i++) {
  1430.               if (StatsBuffer[i].sizetot>0) {
  1431.                 TStamp d = ((TStamp) StatsBuffer[i].size * 1000);
  1432.                 d = d / ((TStamp) StatsBuffer[i].sizetot);
  1433.                 StatsBuffer[i].offset = (int) d;
  1434.               } else
  1435.                 StatsBuffer[i].offset = 0;
  1436.             }
  1437.           }
  1438.           
  1439.           if (!parsing)
  1440.             inprogress->m_sl0.SetRange(0,1000);
  1441.           inprogress->m_sl1.SetRange(0,1000);
  1442.           inprogress->m_sl2.SetRange(0,1000);
  1443.           inprogress->m_sl3.SetRange(0,1000);
  1444.           inprogress->m_sl4.SetRange(0,1000);
  1445.           inprogress->m_sl5.SetRange(0,1000);
  1446.           inprogress->m_sl6.SetRange(0,1000);
  1447.           inprogress->m_sl7.SetRange(0,1000);
  1448.           inprogress->m_sl8.SetRange(0,1000);
  1449.           inprogress->m_sl9.SetRange(0,1000);
  1450.           inprogress->m_sl10.SetRange(0,1000);
  1451.           inprogress->m_sl11.SetRange(0,1000);
  1452.           inprogress->m_sl12.SetRange(0,1000);
  1453.           inprogress->m_sl13.SetRange(0,1000);
  1454.           
  1455.           if (!parsing)
  1456.             inprogress->m_sl0.SetPos(StatsBuffer[0].offset);
  1457.           inprogress->m_sl1.SetPos(StatsBuffer[1].offset);
  1458.           inprogress->m_sl2.SetPos(StatsBuffer[2].offset);
  1459.           inprogress->m_sl3.SetPos(StatsBuffer[3].offset);
  1460.           inprogress->m_sl4.SetPos(StatsBuffer[4].offset);
  1461.           inprogress->m_sl5.SetPos(StatsBuffer[5].offset);
  1462.           inprogress->m_sl6.SetPos(StatsBuffer[6].offset);
  1463.           inprogress->m_sl7.SetPos(StatsBuffer[7].offset);
  1464.           inprogress->m_sl8.SetPos(StatsBuffer[8].offset);
  1465.           inprogress->m_sl9.SetPos(StatsBuffer[9].offset);
  1466.           inprogress->m_sl10.SetPos(StatsBuffer[10].offset);
  1467.           inprogress->m_sl11.SetPos(StatsBuffer[11].offset);
  1468.           inprogress->m_sl12.SetPos(StatsBuffer[12].offset);
  1469.           inprogress->m_sl13.SetPos(StatsBuffer[13].offset);
  1470.           
  1471.           // redraw en boucle
  1472.           {
  1473.             int i=0;
  1474.             if (parsing)
  1475.               i++;
  1476.             for( ; i<NStatsBuffer;i++) {
  1477.               CString st;
  1478.               st = StatsBuffer[i].etat;
  1479.               st.Replace("&", "&&");
  1480.               inprogress->element[0][i]->SetWindowText(st);
  1481.               st = StatsBuffer[i].nom;
  1482.               st.Replace("&", "&&");
  1483.               inprogress->element[1][i]->SetWindowText(st);
  1484.               st = StatsBuffer[i].fichier;
  1485.               st.Replace("&", "&&");
  1486.               inprogress->element[4][i]->SetWindowText(st);
  1487.               
  1488.               if ((strlen(StatsBuffer[i].etat)==0) != StatsBuffer[i].actived) {
  1489.                 StatsBuffer[i].actived=!StatsBuffer[i].actived;
  1490.                 if (!StatsBuffer[i].actived)
  1491.                   inprogress->element[3][i]->ModifyStyle(WS_DISABLED,0);
  1492.                 else
  1493.                   inprogress->element[3][i]->ModifyStyle(0,WS_DISABLED);
  1494.                 inprogress->element[3][i]->RedrawWindow();
  1495.               }
  1496.             }
  1497.           }
  1498.           //
  1499.         }
  1500.         /* else*/
  1501.         if (parsing) {  // parsing
  1502.           //
  1503.           inprogress->m_sl0.SetRange(0,100);
  1504.           inprogress->m_sl0.SetPos(parsing);
  1505.           inprogress->element[0][0]->SetWindowText(LANG(LANG_F14 /*"scanning","parcours"*/));
  1506.           inprogress->element[1][0]->SetWindowText(StatsBuffer[0].nom);
  1507.           inprogress->element[4][0]->SetWindowText("");
  1508.           //inprogress->element[0][1]->SetWindowText();
  1509.         }
  1510.         
  1511.       }
  1512.       {
  1513.         static char last_info[256]="";
  1514.         char info[256];
  1515.         if ((SInfo.stat_nsocket==-1)) {
  1516. #if USE_RAS
  1517.           if (!has_started)
  1518. #endif
  1519.             inprogress->SetDlgItemText(IDC_nm0,LANG(LANG_F15 /*"Waiting for specific hour to start","Attente de l'heure programmΘe pour dΘmarrer"*/));
  1520. #if USE_RAS
  1521.           else
  1522.             inprogress->SetDlgItemText(IDC_nm0,LANG(LANG_F16 /*"Connecting to provider","Connexion au provider"*/));
  1523. #endif
  1524.           inprogress->m_sl0.SetRange(0,SInfo.ft);
  1525.           inprogress->m_sl0.SetPos(SInfo.ft-SInfo.stat_time);  // temps restant
  1526.           // inprogress->SetDlgItemText(IDC_nm1,_SN(ft));
  1527.           if (icn && (!this_CSplitterFrame->iconifie)) {  // minimisΘe mais pas en icone
  1528.             sprintf(info,"[%d s]",SInfo.stat_time);
  1529.           } else {
  1530.             sprintf(info,LANG(LANG_F17 /*"Mirror waiting [%d seconds]","Miroir en attente [%d secondes]"*/),SInfo.stat_time);
  1531.           }
  1532.         } else {
  1533.           if (icn) {  // minimisΘe
  1534.             sprintf(info,"[%s]",lnk);
  1535.           } else {
  1536.             char byteb[256];
  1537.             sprintf(byteb, LLintP, SInfo.stat_bytes);
  1538.             sprintf(info,LANG(LANG_F18),lnk,byteb);
  1539.           }
  1540.         }
  1541.         if (strcmp(info,last_info)) {       /* a changΘ */
  1542.           strcpybuff(last_info,info);           /* recopier */
  1543.           if (this_CSplitterFrame->iconifie)  // minimisΘ icone
  1544.             this_CSplitterFrame->IconChange(last_info);
  1545.           else
  1546.             this_app->GetMainWnd()->SetWindowText(last_info);
  1547.         }
  1548.       }  
  1549.       
  1550.       //inprogress->UpdateWindow();
  1551.     } else {
  1552.     }
  1553.   }
  1554.   // WHTT_UNLOCK();
  1555.   return 1;
  1556. }
  1557.  
  1558. /*
  1559. // refresh scan
  1560. int inprogress_refresh_scan() {
  1561. if ((!termine) && (!termine_requested) && (inprogress->m_hWnd)) {
  1562. if (!SInfo.refresh) {
  1563. if (!inprogress->IsIconic()) {
  1564. int n;
  1565. // patch pour le scanning
  1566. if (n=hts_is_parsing()) {
  1567. strcpybuff(StatsBuffer[0].etat,"scanning");
  1568. inprogress->element[0][0]->SetWindowText("scanning");
  1569. StatsBuffer[0].sizetot=100;
  1570. StatsBuffer[0].size=n;
  1571. inprogress->m_sl0.SetRange(0,100);  // progression en % du scanning
  1572. inprogress->m_sl0.SetPos(n);
  1573. //} else {
  1574. //  inprogress->element[0][0]->SetWindowText("...");
  1575. }
  1576. }
  1577. }
  1578. }
  1579. return 1;
  1580. }
  1581. */
  1582.  
  1583. /* Plantages si DoModal() dans un thread != du principal.. passons.. */
  1584. char* __cdecl httrackengine_query(char* question) {
  1585.   strcpybuff(WIZ_question,question);
  1586.   AfxGetMainWnd()->SendMessage(WM_COMMAND,wm_WizRequest1,0);
  1587.   return WIZ_reponse;
  1588. }
  1589.  
  1590. char* __cdecl httrackengine_query2(char* question) {
  1591.   strcpybuff(WIZ_question,question);
  1592.   AfxGetMainWnd()->SendMessage(WM_COMMAND,wm_WizRequest2,0);
  1593.   return WIZ_reponse;
  1594. }
  1595.  
  1596. char* __cdecl httrackengine_query3(char* question) {
  1597.   strcpybuff(WIZ_question,question);
  1598.   AfxGetMainWnd()->SendMessage(WM_COMMAND,wm_WizRequest3,0);
  1599.   return WIZ_reponse;
  1600. }
  1601.  
  1602. void __cdecl httrackengine_pause(char* lockfile) {
  1603.   AfxMessageBox("Engine paused.. click OK to continue!",MB_OK);
  1604.   remove(lockfile);
  1605. }
  1606.  
  1607. // modif RX 10/10/98 pour gestion des , et des tabs
  1608. char* connversion(char* chaine)
  1609. {
  1610.   for(int i=0;i < (int) strlen(chaine);i++) 
  1611.     if(chaine[i]=='\n') chaine[i]=' ';
  1612.     else if(chaine[i]==13) chaine[i]=' ';
  1613.     else if(chaine[i]==9) chaine[i]=' ';
  1614.     /*else if(chaine[i]==',') chaine[i]=' ';*/
  1615.     
  1616.     return chaine;
  1617. }
  1618.  
  1619.  
  1620. #if SHELL_MULTITHREAD
  1621. void __cdecl RunBackRobot(void* al_p) {
  1622.   int argc;
  1623.   char** argv;
  1624.   
  1625.   while((!inprogress) && (!termine)) Sleep(10);
  1626.   if (inprogress)
  1627.     while ((!inprogress->m_hWnd) || (termine)) Sleep(10);   // attendre formulaire
  1628.     //Sleep(100);
  1629.     
  1630.     Robot_params* al=(Robot_params*) al_p;
  1631.     argc = al->argc;
  1632.     argv = al->argv;
  1633.     /* launch the engine */
  1634.     hts_init();
  1635.     HTTRACK_result=hts_main(argc,argv);
  1636.     /* clear all vars */
  1637.     WHTT_LOCK();
  1638.     termine=1;
  1639.     WHTT_UNLOCK();
  1640.     hts_uninit();
  1641.     
  1642.     _endthread();
  1643. }
  1644. #endif
  1645.  
  1646. // modifs RX 10/10/98: gestion des ,
  1647. CString change(char* chaine,char c) {
  1648.   int comma=1; int first=1;
  1649.   CString chaine1;
  1650.   for(int i=0;i < (int) strlen(chaine);i++) {
  1651.     switch(chaine[i]) {
  1652.     case 10: case 13: case 9: case ' ': case ',':
  1653.       comma=1; 
  1654.       break;
  1655.     default:
  1656.       if (comma) {
  1657.         if (!first) chaine1 +=' ';
  1658.         else first=0; 
  1659.         chaine1  +=c; 
  1660.         comma=0;
  1661.       }
  1662.       chaine1 += chaine[i]; 
  1663.       break;
  1664.     }
  1665.   }
  1666.   return chaine1;
  1667. }
  1668.  
  1669.  
  1670. // Lancement
  1671. void lance(void) {
  1672.   char *argv[1999];
  1673.   int argc=1;
  1674.   int g=0;
  1675.   int i =0;
  1676.   
  1677.   //
  1678.   if (fp_debug) {
  1679.     fprintf(fp_debug,"Building command line\r\n");
  1680.     fflush(fp_debug);
  1681.   }
  1682.   //
  1683.   LINE[0]='\0';
  1684.   strcpybuff(LINE,"-");
  1685.   if (choixdeb[0]!='W')
  1686.     strcatbuff(LINE,"q");         // quiet
  1687.   
  1688.   if (choixdeb[0]=='/')
  1689.     strcatbuff(LINE,"i");
  1690.   else if (choixdeb[0]!='!')
  1691.     strcatbuff(LINE,choixdeb);
  1692.   // option de profondeur
  1693.   if(strcmp(OPTIONdepth,"")!=0) { 
  1694.     strcatbuff(LINE,"r");
  1695.     strcatbuff(LINE,OPTIONdepth);
  1696.   }
  1697.   if(strcmp(OPTIONextdepth,"")!=0) { 
  1698.     strcatbuff(LINE,"%e");
  1699.     strcatbuff(LINE,OPTIONextdepth);
  1700.   }
  1701.   if(strcmp(OPTIONcache,"")!=0) strcatbuff(LINE,OPTIONcache);
  1702.   if(strcmp(OPTIONnorecatch,"")!=0) strcatbuff(LINE,OPTIONnorecatch);
  1703.   if(strcmp(OPTIONtestall,"")!=0) strcatbuff(LINE,OPTIONtestall);
  1704.   if(strcmp(OPTIONparseall,"")!=0) strcatbuff(LINE,OPTIONparseall);
  1705.   if(strcmp(OPTIONlink,"")!=0) strcatbuff(LINE,OPTIONlink);
  1706.   if(strcmp(OPTIONexternal,"")!=0) strcatbuff(LINE,OPTIONexternal);
  1707.   if(strcmp(OPTIONnopurge,"")!=0) strcatbuff(LINE,OPTIONnopurge);
  1708.   if(strcmp(OPTIONhidepwd,"")!=0) strcatbuff(LINE,OPTIONhidepwd);
  1709.   if(strcmp(OPTIONhidequery,"")!=0) strcatbuff(LINE,OPTIONhidequery);
  1710.   if(strcmp(OPTIONrobots,"")!=0) strcatbuff(LINE,OPTIONrobots);
  1711.   if(strcmp(OPTIONcookies,"")!=0) strcatbuff(LINE,OPTIONcookies);
  1712.   if(strcmp(OPTIONchecktype,"")!=0) strcatbuff(LINE,OPTIONchecktype);
  1713.   if(strcmp(OPTIONparsejava,"")!=0) strcatbuff(LINE,OPTIONparsejava);
  1714.   if(strcmp(OPTIONCache2,"")!=0) strcatbuff(LINE,OPTIONCache2);
  1715.   if(strcmp(OPTIONlogtype,"")!=0) strcatbuff(LINE,OPTIONlogtype);
  1716.   if (strlen(OPTIONhttp10)) strcatbuff(LINE,OPTIONhttp10);
  1717.   if (strlen(OPTIONtoler)) strcatbuff(LINE,OPTIONtoler);
  1718.   if (strlen(OPTIONupdhack)) strcatbuff(LINE,OPTIONupdhack);
  1719.   
  1720.   // si get, ne pas faire
  1721.   if (strcmp(choixdeb,"g")!=0) {
  1722.     if(build[0]=='-') {
  1723.       strcatbuff(LINE," ");
  1724.       strcatbuff(LINE,build);
  1725.       strcatbuff(LINE," -");
  1726.     } else if (strcmp(build,"")!=0) strcatbuff(LINE,build);
  1727.   }
  1728.   strcatbuff(LINE,OPTIONdos);
  1729.   strcatbuff(LINE,OPTIONindex);
  1730.   strcatbuff(LINE,OPTIONindex2);
  1731.   strcatbuff(LINE,OPTIONhtmlfirst);
  1732.   strcatbuff(LINE,filtre);
  1733.   strcatbuff(LINE,OPTIONmax);
  1734.   strcatbuff(LINE,OPTIONfrag);
  1735.   strcatbuff(LINE,OPTIONmaxfile);
  1736.   strcatbuff(LINE,OPTIONconn);
  1737.   strcatbuff(LINE,OPTIONtime);
  1738.   strcatbuff(LINE,OPTIONrate);
  1739.   strcatbuff(LINE,OPTIONretry);
  1740.   strcatbuff(LINE,OPTIONhostquit);
  1741.   strcatbuff(LINE,OPTIONka);
  1742.   strcatbuff(LINE,OPTIONlog);
  1743.   strcatbuff(LINE,OPTIONerrpage);
  1744.   //-->
  1745.   strcatbuff(LINE,OPTIONwaittime);
  1746.   strcatbuff(LINE,OPTIONmaxtime);
  1747.   strcatbuff(LINE,OPTIONmaxrate);
  1748.   strcatbuff(LINE,OPTIONmaxconn);
  1749.   strcatbuff(LINE,OPTIONmaxlinks);
  1750.   strcatbuff(LINE,OPTIONproxyftp);  
  1751.   strcatbuff(LINE,"#f");  // flush
  1752.   
  1753.   if (strcmp(OPTIONuser,"")!=0) {strcatbuff(LINE," ");strcatbuff(LINE,"-F");strcatbuff(LINE," ");strcatbuff(LINE,OPTIONuser);}
  1754.   if (strcmp(OPTIONfooter,"")!=0) {strcatbuff(LINE," ");strcatbuff(LINE,"-%F");strcatbuff(LINE," ");strcatbuff(LINE,OPTIONfooter);}
  1755.   
  1756.   if ((int)strlen(OPTIONproxy)>0) {
  1757.     strcatbuff(LINE," -P ");
  1758.     strcatbuff(LINE,OPTIONproxy);
  1759.     strcatbuff(LINE,":");
  1760.     strcatbuff(LINE,OPTIONport);
  1761.   }
  1762.   
  1763.   if (strnotempty(LANGUAGE_ISO)) {
  1764.     strcatbuff(LINE," -%l \"");
  1765.     strcatbuff(LINE,LANGUAGE_ISO);
  1766.     if (strcmp(LANGUAGE_ISO,"en")!=0)
  1767.       strcatbuff(LINE,", en");
  1768.     strcatbuff(LINE,", *\"");
  1769.   }
  1770.   
  1771.   // mode spider, mettre aprΦs options
  1772.   if (choixdeb[0]=='!') {
  1773.     strcatbuff(LINE," --testlinks");
  1774.   } else if (choixdeb[0]=='Y') {
  1775.     strcatbuff(LINE," --mirrorlinks");
  1776.   }
  1777.   
  1778.   // URLs!!
  1779.   strcatbuff(LINE," ");
  1780.   strcatbuff(LINE,OPTIONurl);
  1781.   
  1782.   // file list
  1783.   if ((int) strlen(OPTIONfilelist)>0) {
  1784.     strcatbuff(LINE," -%L \"");
  1785.     strcatbuff(LINE,OPTIONfilelist);
  1786.     strcatbuff(LINE,"\"");
  1787.   }
  1788.   
  1789.   // chemins
  1790.   if(strcmp(OPTIONpath,"")!=0) {
  1791.     strcatbuff(LINE," ");
  1792.     strcatbuff(LINE,"-O");
  1793.     strcatbuff(LINE," ");
  1794.     strcatbuff(LINE,OPTIONpath);
  1795.   }
  1796.   
  1797.   // buffer -> les + et -
  1798.   if(strcmp(buff_filtres,"")!=0) {
  1799.     //if(strcmp(diafiltre.m_url2 ,"")!=0) {
  1800.     strcatbuff(LINE," ");
  1801.     strcatbuff(LINE,buff_filtres );
  1802.   }
  1803.   
  1804.   // --assume
  1805.   if (strnotempty(buff_MIME)) {
  1806.     strcatbuff(LINE," ");
  1807.     strcatbuff(LINE,buff_MIME );
  1808.   }
  1809.   
  1810.   // ---
  1811.   
  1812.   //
  1813.   if (fp_debug) {
  1814.     fprintf(fp_debug,"Cleaning up command line and counting parameters\r\n");
  1815.     fflush(fp_debug);
  1816.   }
  1817.   //
  1818.   // Θpurer cr,lf,tab - double espace -> espace
  1819.   {
  1820.     char *a;
  1821.     while(a=strchr(LINE,9)) *a=' ';
  1822.     while(a=strchr(LINE,10)) *a=' ';
  1823.     while(a=strchr(LINE,13)) *a=' ';
  1824.   }
  1825.   
  1826.   char LINE_back[65535];
  1827.   strcpybuff(LINE_back,LINE);
  1828.   
  1829.   // couper en morceaux
  1830.   {
  1831.     char* p=LINE;
  1832.     argv[0]="winhttrack";
  1833.     do {
  1834.       argv[argc++]=p;
  1835.       p=next_token(p,0);    // prochain token
  1836.       if (p) {
  1837.         *p=0;    // octet nul (tableau)
  1838.         p++;
  1839.       }            
  1840.     } while(p!=NULL);
  1841.   }
  1842.   
  1843.   //
  1844.   if (fp_debug) {
  1845.     fprintf(fp_debug,"Checking doit.log\r\n");
  1846.     fflush(fp_debug);
  1847.   }
  1848.   //
  1849.   // Ok, on lance!
  1850.   if(!termine) {
  1851.     int result=0;
  1852.     {
  1853.       char path_log[HTS_URLMAXSIZE*2];
  1854.       strcpybuff(path_log,CShellApp_app->end_path_complete);
  1855.       if (strlen(path_log)>0)
  1856.         if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  1857.           strcatbuff(path_log,"/");
  1858.         
  1859.         // on efface le doit.log, pour annuler les parametres anciens et en redΘfinir de nouveaux
  1860.         // c'est ici une logique qui diffΦre de la version en ligne de commande
  1861.         //if ((fexist(fconcat(path_log,"hts-cache/new.dat"))) && (fexist(fconcat(path_log,"hts-cache/new.ndx")))) {  // il existe dΘja un cache prΘcΘdent.. renommer
  1862.         if (fexist(fconcat(path_log,"hts-cache/new.ndx"))) {    // un cache est prΘsent
  1863.           if (fexist(fconcat(path_log,"hts-cache/doit.log")))
  1864.             remove(fconcat(path_log,"hts-cache/doit.log"));
  1865.           FILE* fp=fopen(fconcat(path_log,"hts-cache/doit.log"),"wb");
  1866.           if (fp) fclose(fp);
  1867.         }
  1868.         //}
  1869.     }
  1870.     
  1871.     
  1872.     // ---
  1873.     // LANCER LE MIROIR
  1874.     // ---
  1875.     //
  1876.     if (fp_debug) {
  1877.       fprintf(fp_debug,"Ready to call httrack engine, launching threads\r\n");
  1878.       fflush(fp_debug);
  1879.     }
  1880.     //
  1881. #if SHELL_MULTITHREAD
  1882.     Robot_params al;
  1883.     al.argc=argc;
  1884.     al.argv=argv;
  1885.     _beginthread( RunBackRobot     , 0, (void*) &al);
  1886.     //_beginthread( RefreshBackRobot , 0, NULL);
  1887.     
  1888.     //
  1889.     if (fp_debug) {
  1890.       fprintf(fp_debug,"Threads launched, displaying main dialog\r\n");
  1891.       fflush(fp_debug);
  1892.     }
  1893.     //
  1894.     // domodal du refresh
  1895.     /* XXC A SUPPRIMER */
  1896.     while(!termine) {
  1897.       Sleep(100);
  1898.     }
  1899.     //inprogress->DoModal();
  1900.     WHTT_LOCK();
  1901.     shell_terminated=1;
  1902.     result=HTTRACK_result;
  1903.     termine=1;  
  1904.     WHTT_UNLOCK();
  1905.     //
  1906.     if (fp_debug) {
  1907.       fprintf(fp_debug,"Main dialog exited\r\n");
  1908.       fflush(fp_debug);
  1909.     }
  1910.     //
  1911.     
  1912.     // non multithread
  1913. #else
  1914. #error "Non supportΘ"
  1915. #endif
  1916.  
  1917.     /* Aborted mirror or finished? */
  1918.     {
  1919.       char path_log[HTS_URLMAXSIZE*2];
  1920.       strcpybuff(path_log,CShellApp_app->end_path_complete);
  1921.       if (strlen(path_log)>0)
  1922.         if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  1923.           strcatbuff(path_log,"/");
  1924.         if (soft_term_requested || termine_requested) {
  1925.           FILE* fp=fopen(fconcat(path_log,"hts-cache/interrupted.lock"),"wb");
  1926.           if (fp)
  1927.             fclose(fp);
  1928.         } else
  1929.           remove(fconcat(path_log,"hts-cache/interrupted.lock"));
  1930.     }
  1931.     
  1932.     //SetForegroundWindow();   // yop en premier plan!
  1933.     //
  1934.     if (fp_debug) {
  1935.       fprintf(fp_debug,"Displaying end dialog\r\n");
  1936.       fflush(fp_debug);
  1937.     }
  1938.     //
  1939.     /* New pannel */
  1940.     if (result) {      // erreur?
  1941.       strcpybuff(end_mirror_msg,LANG(LANG_F19 /*"A problem occured during the mirror\n  \"","Un problΦme est survenu pendant le miroir\n  \""*/));
  1942.       strcatbuff(end_mirror_msg,"\"");
  1943.       strcatbuff(end_mirror_msg,hts_errmsg());
  1944.       strcatbuff(end_mirror_msg,"\"");
  1945.       strcatbuff(end_mirror_msg,LANG(LANG_F20 /*"\" \nDuring:\n  ","\" \nDurant:\n  "*/));
  1946.       strcatbuff(end_mirror_msg,"\"");
  1947.       strcatbuff(end_mirror_msg,LINE_back);
  1948.       strcatbuff(end_mirror_msg,"\"");
  1949.       strcatbuff(end_mirror_msg,LANG(LANG_F21 /*"\nSee the log file if necessary.\n\nClick OK to quit WinHTTrack.\n\nThanks for using WinHTTrack!","\nVoir le fichier log au besoin\n\nCliquez sur OK pour quitter WinHTTrack\n\nMerci d'utiliser WinHTTrack."*/));
  1950.       //AfxMessageBox(s,MB_OK+MB_ICONINFORMATION);
  1951.     } else {
  1952.       strcpybuff(end_mirror_msg,LANG(LANG_F22 /*"The mirror is finished.\nClick OK to quit WinHTTrack.\nSee log file(s) if necessary to ensure that everything is OK.\n\nThanks for using WinHTTrack!","Le miroir est terminΘ\nCliquez sur OK pour quitter WinHTTrack\nVoir au besoin les fichiers d'audit pour vΘrifier que tout s'est bien passΘ\n\nMerci d'utiliser WinHTTrack!"*/));
  1953.       //AfxMessageBox("The mirror is finished.\nClic OK to quit WinHTTrack.\nSee log file(s) if necessary to ensure that everything is OK.\n\nThanks for using WinHTTrack!",MB_OK+MB_ICONINFORMATION);
  1954.       //        ShellExecute(0,"open",,"","",);
  1955.     }
  1956. #if USE_RAS
  1957.     // erreur ras
  1958.     if (connected == -1)
  1959.       if ((int) strlen(connected_err) > 0)
  1960.         strcpybuff(end_mirror_msg,connected_err);
  1961. #endif
  1962.       {
  1963.         char pathlog[HTS_URLMAXSIZE*2];
  1964.         strcpybuff(pathlog,dialog0->GetPath());
  1965.         Ciplog form;
  1966.         if (strlen(pathlog)>0)
  1967.           if ((pathlog[strlen(pathlog)-1]!='/') && (pathlog[strlen(pathlog)-1]!='\\'))
  1968.             strcatbuff(pathlog,"/");
  1969.           // fichier log existe ou on est tΘlΘcommandΘ par un !
  1970.           if ( (fsize(fconcat(pathlog,"hts-err.txt")))>0) {
  1971.             strcatbuff(end_mirror_msg,LANG(LANG_F23 /*"\n\nTip: Click [View log file] to see warning or error messages","\n\nConseil: [Voir fichiers log] pour voir les erreurs et messages"*/));
  1972.           }
  1973.       }
  1974.       //this_Cinfoend->m_infoend = msg;
  1975.       inprogress->SendMessage(WM_USER + 4);      // avertir
  1976.       if (fp_debug) {
  1977.         fprintf(fp_debug,"DoModal end dialog, waiting\r\n");
  1978.         fflush(fp_debug);
  1979.       }
  1980.       /*
  1981.       if (info.DoModal() == IDC_NewProject) {     // relancer programme!
  1982.       // copie de onnewproject() de wid1::
  1983.       CWinApp* pApp = AfxGetApp();
  1984.       CString name = pApp->m_pszHelpFilePath;
  1985.       name=name.Left(name.GetLength()-4);
  1986.       name += ".EXE";
  1987.       ShellExecute(NULL,"open",name,"","",SW_RESTORE);    
  1988.       }
  1989.       */
  1990.       if (fp_debug) {
  1991.         fprintf(fp_debug,"Final info OK, leaving..\r\n");
  1992.         fflush(fp_debug);
  1993.       }
  1994.   }
  1995.   else {
  1996.   }
  1997.   
  1998. }
  1999.  
  2000. // int LANG_T(int);
  2001. // char* LANG(char* english,char* francais);
  2002.  
  2003.  
  2004. /* interface lang - lang_string="stringlang0\nstringlang1\n..laststring" */
  2005. void SetCombo(CWnd* _this,int id,char* lang_string) {
  2006.   CComboBox* combo = (CComboBox*) _this->GetDlgItem(id);
  2007.   CString st=lang_string;
  2008.   st.TrimLeft(); st.TrimRight();
  2009.   if (combo) {
  2010.     st+="\n";         /* end */
  2011.     combo->ResetContent();
  2012.     while(st.GetLength()) {
  2013.       int pos=st.Find('\n');
  2014.       CString item=st.Left(pos);
  2015.       st=st.Mid(pos+1);
  2016.       item.TrimLeft(); item.TrimRight();
  2017.       if (item.GetLength())
  2018.         combo->AddString(item);
  2019.     }
  2020.   }
  2021. }
  2022.  
  2023.  
  2024. // Ecriture profiles
  2025. char* profile_code(char* from) {
  2026.   static char buff[65535];
  2027.   int i;
  2028.   int j;
  2029.   for(i=0,j=0;i<(int) strlen(from);i++) {
  2030.     switch(from[i]) {
  2031.     case '%': 
  2032.       buff[j++]='%';
  2033.       buff[j++]='%';
  2034.       break;
  2035.     case '=': 
  2036.       buff[j++]='%';
  2037.       buff[j++]='3';
  2038.       buff[j++]='d';
  2039.       break;
  2040.     case 13:
  2041.       buff[j++]='%';
  2042.       buff[j++]='0';
  2043.       buff[j++]='d';
  2044.       break;
  2045.     case 10:
  2046.       buff[j++]='%';
  2047.       buff[j++]='0';
  2048.       buff[j++]='a';
  2049.       break;
  2050.     case 9:
  2051.       buff[j++]='%';
  2052.       buff[j++]='0';
  2053.       buff[j++]='9';
  2054.       break;
  2055.     default:
  2056.       buff[j++]=from[i];
  2057.       break;
  2058.     }
  2059.   }
  2060.   buff[j++]='\0';
  2061.   return buff;
  2062. }
  2063. char* profile_decode(char* from) {
  2064.   static char buff[2048];
  2065.   int i;
  2066.   int j;
  2067.   for(i=0,j=0;j<(int) strlen(from);i++) {  // oui oui
  2068.     if (from[j]=='%') {
  2069.       if (from[j+1]=='%') {
  2070.         buff[i]='%';
  2071.         j+=2;
  2072.       } else {
  2073.         if (strncmp(from+j+1,"0d",2)==0)
  2074.           buff[i]=13;
  2075.         else if (strncmp(from+j+1,"0a",2)==0)
  2076.           buff[i]=10;
  2077.         else if (strncmp(from+j+1,"09",2)==0)
  2078.           buff[i]=9;
  2079.         else if (strncmp(from+j+1,"3d",2)==0)
  2080.           buff[i]='=';
  2081.         else
  2082.           buff[i]=' ';
  2083.         j+=3;
  2084.       }
  2085.     } else
  2086.       buff[i]=from[j++];
  2087.   }
  2088.   buff[i++]='\0';
  2089.   return buff;
  2090. }
  2091. //
  2092. // Ecriture/Lecture profiles
  2093. int MyWriteProfileInt(CString path,CString dummy,CString name,int value) {
  2094.   if (path.IsEmpty()) {
  2095.     CWinApp* pApp = AfxGetApp();
  2096.     pApp->WriteProfileInt(dummy,name,value);
  2097.   } else if (path=="<mem>") {       // buffer
  2098.     tmpm.setInt(name,value);
  2099.     return 0;
  2100.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2101.     if (tmpf) {
  2102.       return MyWriteProfileIntFile(tmpf,dummy,name,value);
  2103.     }
  2104.   } else {
  2105.     FILE* fp = fopen(path,"ab");
  2106.     if (fp) {
  2107.       int r=MyWriteProfileIntFile(fp,dummy,name,value);
  2108.       /*
  2109.       fprintf(fp,"%s=%d\x0d\x0a",name,value);
  2110.       */
  2111.       fclose(fp);
  2112.       return r;
  2113.     }
  2114.   }
  2115.   return 0;
  2116. }
  2117. int MyWriteProfileIntFile(FILE* fp,CString dummy,CString name,int value) {
  2118.   if (fp) {
  2119.     fprintf(fp,"%s=%d\x0d\x0a",name,value);
  2120.   }
  2121.   return 0;
  2122. }
  2123. int MyWriteProfileString(CString path,CString dummy,CString name,CString value) {
  2124.   if (path.IsEmpty()) {
  2125.     CWinApp* pApp = AfxGetApp();
  2126.     char *tempo;
  2127.     tempo=(char*) malloc(strlen(value)+1);
  2128.     if (tempo) {
  2129.       strcpybuff(tempo,value);
  2130.       pApp->WriteProfileString(dummy,name,profile_code(tempo));
  2131.     } else
  2132.       return -1;      // error
  2133.   } else if (path=="<mem>") {       // buffer
  2134.     tmpm.setString(name,value);
  2135.     return 0;
  2136.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2137.     if (tmpf) {
  2138.       return MyWriteProfileStringFile(tmpf,dummy,name,value);
  2139.     }
  2140.   } else {
  2141.     FILE* fp = fopen(path,"ab");
  2142.     if (fp) {
  2143.       int r=MyWriteProfileStringFile(fp,dummy,name,value);
  2144.       /*
  2145.       char *tempo;
  2146.       tempo=(char*) malloc(strlen(value)+1);
  2147.       if (tempo) {
  2148.       strcpybuff(tempo,value);
  2149.       fprintf(fp,"%s=%s\x0d\x0a",name,profile_code(tempo));
  2150.       fclose(fp);
  2151.       free(tempo);
  2152.       } else
  2153.       return -1;      // error
  2154.       */
  2155.       fclose(fp);
  2156.       return r;
  2157.     }
  2158.   }
  2159.   return 0;
  2160. }
  2161. int MyWriteProfileStringFile(FILE* fp,CString dummy,CString name,CString value) {
  2162.   if (fp) {
  2163.     char *tempo;
  2164.     tempo=(char*) malloc(strlen(value)+1);
  2165.     if (tempo) {
  2166.       strcpybuff(tempo,value);
  2167.       fprintf(fp,"%s=%s\x0d\x0a",name,profile_code(tempo));
  2168.       free(tempo);
  2169.     } else
  2170.       return -1;      // error
  2171.   }
  2172.   return 0;
  2173. }
  2174. //
  2175. // lecture
  2176. int MyGetProfileInt(CString path,CString dummy,CString name,int value) {
  2177.   if (path.IsEmpty()) {
  2178.     CWinApp* pApp = AfxGetApp();
  2179.     return pApp->GetProfileInt(dummy,name,value);
  2180.   } else if (path=="<mem>") {       // buffer
  2181.     return tmpm.getInt(name,value);
  2182.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2183.     if (tmpf) {
  2184.       return MyGetProfileIntFile(tmpf,dummy,name,value);
  2185.     } else return value;
  2186.   } else {
  2187.     FILE* fp = fopen(path,"rb");
  2188.     if (fp) {
  2189.       int r=MyGetProfileIntFile(fp,dummy,name,value);
  2190.       /*
  2191.       char srch[256];
  2192.       sprintf(srch,"%s=",name);
  2193.       while(!feof(fp)) {
  2194.       char s[HTS_URLMAXSIZE*2];
  2195.       linput(fp,s,1020);
  2196.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2197.       int val;
  2198.       if (sscanf(s+strlen(srch),"%d",&val) == 1)
  2199.       return val;
  2200.       else
  2201.       return value;
  2202.       }
  2203.       }
  2204.       fclose(fp);
  2205.       return value;
  2206.       */
  2207.       fclose(fp);
  2208.       return r;
  2209.     } else return value;
  2210.   }
  2211. }
  2212. int MyGetProfileIntFile(FILE* fp,CString dummy,CString name,int value) {
  2213.   if (fp) {
  2214.     char srch[256];
  2215.     fseek(fp,0,SEEK_SET);
  2216.     sprintf(srch,"%s=",name);
  2217.     while(!feof(fp)) {
  2218.       char s[2048]; s[0]='\0';
  2219.       linput(fp,s,2000);
  2220.       if (strlen(s)==0)     // EOF
  2221.         return value;
  2222.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2223.         int val;
  2224.         if (sscanf(s+strlen(srch),"%d",&val) == 1)
  2225.           return val;
  2226.         else
  2227.           return value;
  2228.       }
  2229.     }
  2230.     return value;
  2231.   } else return value;
  2232. }
  2233. CString MyGetProfileString(CString path,CString dummy,CString name,CString value) {
  2234.   if (path.IsEmpty()) {
  2235.     CWinApp* pApp = AfxGetApp();
  2236.     char tempo[32768];
  2237.     char value_default[32768];
  2238.     strcpybuff(value_default,value);
  2239.     strcpybuff(tempo,pApp->GetProfileString(dummy,name,profile_code(value_default)));
  2240.     return profile_decode(tempo);
  2241.   } else if (path=="<mem>") {       // buffer
  2242.     return tmpm.getString(name,value);
  2243.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2244.     if (tmpf) {
  2245.       return MyGetProfileStringFile(tmpf,dummy,name,value);
  2246.     } else return value;
  2247.   } else {
  2248.     FILE* fp = fopen(path,"rb");
  2249.     if (fp) {
  2250.       CString st=MyGetProfileStringFile(fp,dummy,name,value);
  2251.       /*
  2252.       char srch[256];
  2253.       sprintf(srch,"%s",name);
  2254.       strcatbuff(srch,"=");
  2255.       while(!feof(fp)) {
  2256.       char s[32768];
  2257.       linput(fp,s,32000);
  2258.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2259.       return profile_decode(s+strlen(srch));
  2260.       }
  2261.       }
  2262.       fclose(fp);
  2263.       return value;
  2264.       */
  2265.       fclose(fp);
  2266.       return st;
  2267.     } else return value;
  2268.   }
  2269. }
  2270. CString MyGetProfileStringFile(FILE* fp,CString dummy,CString name,CString value) {
  2271.   if (fp) {
  2272.     char srch[256];
  2273.     fseek(fp,0,SEEK_SET);
  2274.     sprintf(srch,"%s",name);
  2275.     strcatbuff(srch,"=");
  2276.     while(!feof(fp)) {
  2277.       char s[32768]; s[0]='\0';
  2278.       linput(fp,s,32000);
  2279.       if (strlen(s)==0)     // EOF
  2280.         return value;
  2281.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2282.         return profile_decode(s+strlen(srch));
  2283.       }
  2284.     }
  2285.     return value;
  2286.   } else return value;
  2287. }
  2288.  
  2289. //
  2290. // Get_profile et Write_profile eux mΩmes
  2291. //
  2292. // path="" -> Θcrire dans la base (default)
  2293. // path="<tmp>" -> Θcrire dans le fichier tempo commun
  2294. // path="<mem>" -> Θcrire dans le buffer tempo commun
  2295. // path="<null>" -> lire default (illΘgal en Θcriture)
  2296. void Write_profile(CString path,int load_path) {
  2297.   CWaitCursor wait;
  2298.   CString strSection       = "OptionsValues";
  2299.   CString st;
  2300.   int n;
  2301.   
  2302.   // Fichier tempo ou fichier?
  2303.   if (path=="<tmp>") {     // fichier temporaire
  2304.     if (tmpf)
  2305.       fclose(tmpf);
  2306.     tmpf=tmpfile();
  2307.     if (!tmpf)
  2308.       return;
  2309.   } else if (path=="<mem>") {     // buffer temporaire
  2310.     tmpm.deleteAll();
  2311.   } else if (!(path.IsEmpty())) {
  2312.     FILE *fp=fopen(path,"wb");
  2313.     if (fp) 
  2314.       fclose(fp);
  2315.   }
  2316.   
  2317.   //if (dialog3.m_hWnd == NULL) {    // pas initialisΘ
  2318.   if (maintab->m_hWnd == NULL) {    // pas initialisΘ
  2319.     // checkboxes
  2320.     MyWriteProfileInt(path,strSection, "Near",maintab->m_option1.m_link);
  2321.     MyWriteProfileInt(path,strSection, "Test",maintab->m_option1.m_testall);
  2322.     MyWriteProfileInt(path,strSection, "ParseAll",maintab->m_option1.m_parseall);
  2323.     MyWriteProfileInt(path,strSection, "HTMLFirst",maintab->m_option1.m_htmlfirst);
  2324.     MyWriteProfileInt(path,strSection, "Cache",maintab->m_option3.m_cache);
  2325.     MyWriteProfileInt(path,strSection, "NoRecatch",maintab->m_option9.m_norecatch);
  2326.     MyWriteProfileInt(path,strSection, "Dos",
  2327.       ((maintab->m_option2.m_dos)?1:0)
  2328.       +
  2329.       (((maintab->m_option2.m_iso9660)?1:0)<<1)
  2330.       );
  2331.     MyWriteProfileInt(path,strSection, "Index",maintab->m_option9.m_index);
  2332.     MyWriteProfileInt(path,strSection, "WordIndex",maintab->m_option9.m_index2);
  2333.     MyWriteProfileInt(path,strSection, "Log",maintab->m_option9.m_logf);
  2334.     MyWriteProfileInt(path,strSection, "RemoveTimeout",maintab->m_option4.m_remt);
  2335.     MyWriteProfileInt(path,strSection, "RemoveRateout",maintab->m_option4.m_rems);
  2336.     MyWriteProfileInt(path,strSection, "KeepAlive",maintab->m_option4.m_ka);
  2337.     MyWriteProfileInt(path,strSection, "FollowRobotsTxt",maintab->m_option8.m_robots);
  2338.     MyWriteProfileInt(path,strSection, "NoErrorPages",maintab->m_option2.m_errpage);
  2339.     MyWriteProfileInt(path,strSection, "NoExternalPages",maintab->m_option2.m_external);
  2340.     MyWriteProfileInt(path,strSection, "NoPwdInPages",maintab->m_option2.m_hidepwd);
  2341.     MyWriteProfileInt(path,strSection, "NoQueryStrings",maintab->m_option2.m_hidequery);
  2342.     MyWriteProfileInt(path,strSection, "NoPurgeOldFiles",maintab->m_option2.m_nopurge);
  2343.     MyWriteProfileInt(path,strSection, "Cookies",maintab->m_option8.m_cookies);
  2344.     MyWriteProfileInt(path,strSection, "CheckType",maintab->m_option8.m_checktype);
  2345.     MyWriteProfileInt(path,strSection, "ParseJava",maintab->m_option8.m_parsejava);
  2346.     MyWriteProfileInt(path,strSection, "HTTP10",maintab->m_option8.m_http10);
  2347.     MyWriteProfileInt(path,strSection, "TolerantRequests",maintab->m_option8.m_toler);
  2348.     MyWriteProfileInt(path,strSection, "UpdateHack",maintab->m_option8.m_updhack);
  2349.     MyWriteProfileInt(path,strSection, "StoreAllInCache",maintab->m_option9.m_Cache2);
  2350.     MyWriteProfileInt(path,strSection, "LogType",maintab->m_option9.m_logtype);
  2351.     MyWriteProfileInt(path,strSection, "UseHTTPProxyForFTP",maintab->m_option10.m_ftpprox);
  2352.     
  2353.     // menus
  2354.     MyWriteProfileInt(path,strSection, "Build",maintab->m_option2.m_build);
  2355.     MyWriteProfileInt(path,strSection, "PrimaryScan",maintab->m_option3.m_filter);
  2356.     MyWriteProfileInt(path,strSection, "Travel",maintab->m_option3.m_travel);
  2357.     MyWriteProfileInt(path,strSection, "GlobalTravel",maintab->m_option3.m_travel2);
  2358.     MyWriteProfileInt(path,strSection, "RewriteLinks",maintab->m_option3.m_travel3);
  2359.     MyWriteProfileString(path,strSection, "BuildString",maintab->m_option2.Bopt.m_BuildString);
  2360.     
  2361.     // champs
  2362.     MyWriteProfileString(path,strSection, "MaxHtml",maintab->m_option5.m_maxhtml);
  2363.     MyWriteProfileString(path,strSection, "MaxOther",maintab->m_option5.m_othermax);
  2364.     MyWriteProfileString(path,strSection, "MaxAll",maintab->m_option5.m_sizemax);
  2365.     MyWriteProfileString(path,strSection, "MaxWait",maintab->m_option5.m_pausebytes);
  2366.     MyWriteProfileString(path,strSection, "Sockets",maintab->m_option4.m_connexion);
  2367.     MyWriteProfileString(path,strSection, "Retry",maintab->m_option4.m_retry);
  2368.     MyWriteProfileString(path,strSection, "MaxTime",maintab->m_option5.m_maxtime);
  2369.     MyWriteProfileString(path,strSection, "TimeOut",maintab->m_option4.m_timeout);
  2370.     MyWriteProfileString(path,strSection, "RateOut",maintab->m_option4.m_rate);
  2371.     MyWriteProfileString(path,strSection, "UserID",maintab->m_option6.m_user);
  2372.     MyWriteProfileString(path,strSection, "Footer",maintab->m_option6.m_footer);
  2373.     MyWriteProfileString(path,strSection, "MaxRate",maintab->m_option5.m_maxrate);
  2374.     MyWriteProfileString(path,strSection, "WildCardFilters",maintab->m_option7.m_url2);
  2375.     MyWriteProfileString(path,strSection, "Proxy",maintab->m_option10.m_proxy);
  2376.     MyWriteProfileString(path,strSection, "Port",maintab->m_option10.m_port);
  2377.     MyWriteProfileString(path,strSection, "Depth",maintab->m_option5.m_depth);
  2378.     MyWriteProfileString(path,strSection, "ExtDepth",maintab->m_option5.m_depth2);
  2379.     MyWriteProfileString(path,strSection, "MaxConn",maintab->m_option5.m_maxconn);    
  2380.     MyWriteProfileString(path,strSection, "MaxLinks",maintab->m_option5.m_maxlinks);    
  2381.     
  2382.     // 11
  2383.     MyWriteProfileString(path,strSection, "MIMEDefsExt1",maintab->m_option11.m_ext1);    
  2384.     MyWriteProfileString(path,strSection, "MIMEDefsExt2",maintab->m_option11.m_ext2);    
  2385.     MyWriteProfileString(path,strSection, "MIMEDefsExt3",maintab->m_option11.m_ext3);    
  2386.     MyWriteProfileString(path,strSection, "MIMEDefsExt4",maintab->m_option11.m_ext4);    
  2387.     MyWriteProfileString(path,strSection, "MIMEDefsExt5",maintab->m_option11.m_ext5);    
  2388.     MyWriteProfileString(path,strSection, "MIMEDefsExt6",maintab->m_option11.m_ext6);    
  2389.     MyWriteProfileString(path,strSection, "MIMEDefsExt7",maintab->m_option11.m_ext7);    
  2390.     MyWriteProfileString(path,strSection, "MIMEDefsExt8",maintab->m_option11.m_ext8);    
  2391.     MyWriteProfileString(path,strSection, "MIMEDefsMime1",maintab->m_option11.m_mime1);    
  2392.     MyWriteProfileString(path,strSection, "MIMEDefsMime2",maintab->m_option11.m_mime2);    
  2393.     MyWriteProfileString(path,strSection, "MIMEDefsMime3",maintab->m_option11.m_mime3);    
  2394.     MyWriteProfileString(path,strSection, "MIMEDefsMime4",maintab->m_option11.m_mime4);    
  2395.     MyWriteProfileString(path,strSection, "MIMEDefsMime5",maintab->m_option11.m_mime5);    
  2396.     MyWriteProfileString(path,strSection, "MIMEDefsMime6",maintab->m_option11.m_mime6);    
  2397.     MyWriteProfileString(path,strSection, "MIMEDefsMime7",maintab->m_option11.m_mime7);    
  2398.     MyWriteProfileString(path,strSection, "MIMEDefsMime8",maintab->m_option11.m_mime8);    
  2399.   } else {
  2400.     // checkboxes
  2401.     // 1
  2402.     n=maintab->m_option1.IsDlgButtonChecked(IDC_link);
  2403.     MyWriteProfileInt(path,strSection,"Near", n);
  2404.     n=maintab->m_option1.IsDlgButtonChecked(IDC_testall);
  2405.     MyWriteProfileInt(path,strSection,"Test", n);
  2406.     n=maintab->m_option1.IsDlgButtonChecked(IDC_parseall);
  2407.     MyWriteProfileInt(path,strSection,"ParseAll", n);
  2408.     n=maintab->m_option1.IsDlgButtonChecked(IDC_htmlfirst);
  2409.     MyWriteProfileInt(path,strSection,"HTMLFirst", n);
  2410.     // 2
  2411.     n=maintab->m_option3.IsDlgButtonChecked(IDC_Cache);
  2412.     MyWriteProfileInt(path,strSection,"Cache", n);
  2413.     n=maintab->m_option2.IsDlgButtonChecked(IDC_norecatch);
  2414.     MyWriteProfileInt(path,strSection,"NoRecatch", n);
  2415.     n = ((maintab->m_option2.IsDlgButtonChecked(IDC_dos))?1:0)
  2416.       + ((maintab->m_option2.IsDlgButtonChecked(IDC_iso9660)?1:0)<<1);
  2417.     MyWriteProfileInt(path,strSection,"Dos", n);
  2418.     n=maintab->m_option2.IsDlgButtonChecked(IDC_index);
  2419.     MyWriteProfileInt(path,strSection,"Index", n);
  2420.     n=maintab->m_option2.IsDlgButtonChecked(IDC_index2);
  2421.     MyWriteProfileInt(path,strSection,"WordIndex", n);
  2422.     n=maintab->m_option2.IsDlgButtonChecked(IDC_logf);
  2423.     MyWriteProfileInt(path,strSection,"Log", n);
  2424.     n=maintab->m_option2.IsDlgButtonChecked(IDC_errpage);
  2425.     MyWriteProfileInt(path,strSection,"NoErrorPages", n);
  2426.     n=maintab->m_option2.IsDlgButtonChecked(IDC_hidepwd);
  2427.     MyWriteProfileInt(path,strSection,"NoPwdInPages", n);
  2428.     n=maintab->m_option2.IsDlgButtonChecked(IDC_hidequery);
  2429.     MyWriteProfileInt(path,strSection,"NoQueryStrings", n);
  2430.     n=maintab->m_option2.IsDlgButtonChecked(IDC_external);
  2431.     MyWriteProfileInt(path,strSection,"NoExternalPages", n);
  2432.     n=maintab->m_option2.IsDlgButtonChecked(IDC_nopurge);
  2433.     MyWriteProfileInt(path,strSection,"NoPurgeOldFiles", n);
  2434.     if ((n=maintab->m_option2.m_ctl_build.GetCurSel()) != CB_ERR)
  2435.       MyWriteProfileInt(path,strSection, "Build", n);
  2436.     st = maintab->m_option2.Bopt.m_BuildString;
  2437.     if (st.GetLength()>0)
  2438.       MyWriteProfileString(path,strSection, "BuildString",st);
  2439.     // 3
  2440.     // menus
  2441.     if ((n=maintab->m_option3.m_ctl_filter.GetCurSel()) != CB_ERR)
  2442.       MyWriteProfileInt(path,strSection, "PrimaryScan", n);
  2443.     if ((n=maintab->m_option3.m_ctl_travel.GetCurSel()) != CB_ERR)
  2444.       MyWriteProfileInt(path,strSection, "Travel", n);
  2445.     if ((n=maintab->m_option3.m_ctl_travel2.GetCurSel()) != CB_ERR)
  2446.       MyWriteProfileInt(path,strSection, "GlobalTravel", n);
  2447.     if ((n=maintab->m_option3.m_ctl_travel3.GetCurSel()) != CB_ERR)
  2448.       MyWriteProfileInt(path,strSection, "RewriteLinks", n);
  2449.     //
  2450.     maintab->m_option8.GetDlgItemText(IDC_robots,st);
  2451.     MyWriteProfileString(path,strSection, "FollowRobotsTxt", st);
  2452.     // 4
  2453.     maintab->m_option4.GetDlgItemText(IDC_connexion,st);
  2454.     MyWriteProfileString(path,strSection, "Sockets", st);
  2455.     maintab->m_option4.GetDlgItemText(IDC_timeout,st);
  2456.     MyWriteProfileString(path,strSection, "TimeOut", st);
  2457.     n=maintab->m_option4.IsDlgButtonChecked(IDC_remt);
  2458.     MyWriteProfileInt(path,strSection,"RemoveTimeout", n);
  2459.     maintab->m_option4.GetDlgItemText(IDC_retry,st);
  2460.     MyWriteProfileString(path,strSection, "Retry", st);
  2461.     maintab->m_option4.GetDlgItemText(IDC_rate,st);
  2462.     MyWriteProfileString(path,strSection, "RateOut", st);
  2463.     n=maintab->m_option4.IsDlgButtonChecked(IDC_rems);
  2464.     MyWriteProfileInt(path,strSection,"RemoveRateout", n);
  2465.     n=maintab->m_option4.IsDlgButtonChecked(IDC_ka);
  2466.     MyWriteProfileInt(path,strSection,"KeepAlive", n);
  2467.     // 5
  2468.     maintab->m_option5.GetDlgItemText(IDC_maxhtml,st);
  2469.     MyWriteProfileString(path,strSection, "MaxHtml", st);
  2470.     maintab->m_option5.GetDlgItemText(IDC_othermax,st);
  2471.     MyWriteProfileString(path,strSection, "MaxOther", st);
  2472.     maintab->m_option5.GetDlgItemText(IDC_sizemax,st);
  2473.     MyWriteProfileString(path,strSection, "MaxAll", st);
  2474.     maintab->m_option5.GetDlgItemText(IDC_pausebytes,st);
  2475.     MyWriteProfileString(path,strSection, "MaxWait", st);
  2476.     maintab->m_option5.GetDlgItemText(IDC_maxtime,st);
  2477.     MyWriteProfileString(path,strSection, "MaxTime", st);
  2478.     maintab->m_option5.GetDlgItemText(IDC_maxrate,st);
  2479.     MyWriteProfileString(path,strSection, "MaxRate", st);
  2480.     maintab->m_option5.GetDlgItemText(IDC_depth,st);
  2481.     MyWriteProfileString(path,strSection,"Depth",st);
  2482.     maintab->m_option5.GetDlgItemText(IDC_depth2,st);
  2483.     MyWriteProfileString(path,strSection,"ExtDepth",st);
  2484.     maintab->m_option5.GetDlgItemText(IDC_maxconn,st);
  2485.     MyWriteProfileString(path,strSection, "MaxConn", st);
  2486.     maintab->m_option5.GetDlgItemText(IDC_maxlinks,st);
  2487.     MyWriteProfileString(path,strSection, "MaxLinks", st);
  2488.     // 6
  2489.     maintab->m_option6.GetDlgItemText(IDC_user,st);
  2490.     MyWriteProfileString(path,strSection, "UserID", st);
  2491.     maintab->m_option6.GetDlgItemText(IDC_footer,st);
  2492.     MyWriteProfileString(path,strSection, "Footer", st);
  2493.     // 7
  2494.     maintab->m_option7.GetDlgItemText(IDC_URL2,st);
  2495.     MyWriteProfileString(path,strSection, "WildCardFilters", st);
  2496.     // 8
  2497.     maintab->m_option8.GetDlgItemText(IDC_cookies,st);
  2498.     MyWriteProfileString(path,strSection, "Cookies", st);
  2499.     maintab->m_option8.GetDlgItemText(IDC_checktype,st);
  2500.     MyWriteProfileString(path,strSection, "CheckType", st);
  2501.     n=maintab->m_option8.IsDlgButtonChecked(IDC_parsejava);
  2502.     MyWriteProfileInt(path,strSection, "ParseJava", n);
  2503.     n=maintab->m_option8.IsDlgButtonChecked(IDC_http10);
  2504.     MyWriteProfileInt(path,strSection, "HTTP10", n);
  2505.     n=maintab->m_option8.IsDlgButtonChecked(IDC_toler);
  2506.     MyWriteProfileInt(path,strSection, "TolerantRequests", n);
  2507.     n=maintab->m_option8.IsDlgButtonChecked(IDC_updhack);
  2508.     MyWriteProfileInt(path,strSection, "UpdateHack", n);
  2509.     // 9
  2510.     maintab->m_option9.GetDlgItemText(IDC_Cache2,st);
  2511.     MyWriteProfileString(path,strSection, "StoreAllInCache", st);
  2512.     maintab->m_option9.GetDlgItemText(IDC_logtype,st);
  2513.     MyWriteProfileString(path,strSection, "LogType", st);
  2514.     // 10
  2515.     maintab->m_option10.GetDlgItemText(IDC_prox,st);
  2516.     MyWriteProfileString(path,strSection,"Proxy",st);
  2517.     maintab->m_option10.GetDlgItemText(IDC_proxport,st);
  2518.     MyWriteProfileString(path,strSection,"Port",st);
  2519.     n=maintab->m_option10.IsDlgButtonChecked(IDC_ftpprox);
  2520.     MyWriteProfileInt(path,strSection,"UseHTTPProxyForFTP", n);
  2521.     
  2522.     // 11
  2523.     maintab->m_option11.GetDlgItemText(IDC_ext1,st); MyWriteProfileString(path,strSection,"MIMEDefsExt1",st);
  2524.     maintab->m_option11.GetDlgItemText(IDC_ext2,st); MyWriteProfileString(path,strSection,"MIMEDefsExt2",st);
  2525.     maintab->m_option11.GetDlgItemText(IDC_ext3,st); MyWriteProfileString(path,strSection,"MIMEDefsExt3",st);
  2526.     maintab->m_option11.GetDlgItemText(IDC_ext4,st); MyWriteProfileString(path,strSection,"MIMEDefsExt4",st);
  2527.     maintab->m_option11.GetDlgItemText(IDC_ext5,st); MyWriteProfileString(path,strSection,"MIMEDefsExt5",st);
  2528.     maintab->m_option11.GetDlgItemText(IDC_ext6,st); MyWriteProfileString(path,strSection,"MIMEDefsExt6",st);
  2529.     maintab->m_option11.GetDlgItemText(IDC_ext7,st); MyWriteProfileString(path,strSection,"MIMEDefsExt7",st);
  2530.     maintab->m_option11.GetDlgItemText(IDC_ext8,st); MyWriteProfileString(path,strSection,"MIMEDefsExt8",st);
  2531.     maintab->m_option11.GetDlgItemText(IDC_mime1,st); MyWriteProfileString(path,strSection,"MIMEDefsMime1",st);
  2532.     maintab->m_option11.GetDlgItemText(IDC_mime2,st); MyWriteProfileString(path,strSection,"MIMEDefsMime2",st);
  2533.     maintab->m_option11.GetDlgItemText(IDC_mime3,st); MyWriteProfileString(path,strSection,"MIMEDefsMime3",st);
  2534.     maintab->m_option11.GetDlgItemText(IDC_mime4,st); MyWriteProfileString(path,strSection,"MIMEDefsMime4",st);
  2535.     maintab->m_option11.GetDlgItemText(IDC_mime5,st); MyWriteProfileString(path,strSection,"MIMEDefsMime5",st);
  2536.     maintab->m_option11.GetDlgItemText(IDC_mime6,st); MyWriteProfileString(path,strSection,"MIMEDefsMime6",st);
  2537.     maintab->m_option11.GetDlgItemText(IDC_mime7,st); MyWriteProfileString(path,strSection,"MIMEDefsMime7",st);
  2538.     maintab->m_option11.GetDlgItemText(IDC_mime8,st); MyWriteProfileString(path,strSection,"MIMEDefsMime8",st);
  2539.   }
  2540.   // liens, jokers etc. si mirror merge
  2541.   if (!(path.IsEmpty())) {
  2542.     if (dialog1->m_hWnd == NULL) {    // pas initialisΘ
  2543.       //MyWriteProfileString(path,strSection,"CurrentDepth",dialog1->m_depth);
  2544.       MyWriteProfileString(path,strSection,"CurrentUrl",dialog1->m_urls);
  2545.       if (dialog1->m_todo >= 0)
  2546.         MyWriteProfileInt(path, strSection,"CurrentAction", dialog1->m_todo);
  2547.       //
  2548.       MyWriteProfileString(path,strSection,"CurrentURLList",dialog1->m_filelist);
  2549.       
  2550.       //if (load_path) {
  2551.       //MyWriteProfileString(path,strSection,"CurrentPath1",dialog0->GetPath());
  2552.       //MyWriteProfileString(path,strSection,"CurrentPath2",dialog0->GetPath());
  2553.       //}
  2554.     } else {
  2555.       //dialog1->GetDlgItemText(IDC_depth,st);
  2556.       //MyWriteProfileString(path,strSection,"CurrentDepth",st);
  2557.       dialog1->GetDlgItemText(IDC_URL,st);
  2558.       MyWriteProfileString(path,strSection,"CurrentUrl",st);
  2559.       if ((n=dialog1->m_ctl_todo.GetCurSel()) != CB_ERR)
  2560.         MyWriteProfileInt(path,strSection, "CurrentAction", n);
  2561.       //
  2562.       dialog1->GetDlgItemText(IDC_filelist,st);
  2563.       MyWriteProfileString(path,strSection,"CurrentURLList",st);
  2564.       //
  2565.       //if (load_path) {
  2566.       //dialog1->GetDlgItemText(IDC_pathlog,st);
  2567.       //MyWriteProfileString(path,strSection,"CurrentPath1",st);
  2568.       //dialog1->GetDlgItemText(IDC_pthmir,st);
  2569.       //MyWriteProfileString(path,strSection,"CurrentPath2",st);
  2570.       //}
  2571.     }
  2572.   }
  2573. }
  2574. // path="" -> lire dans la base (default)
  2575. //if not exist: do not load anything but patches projname&co
  2576. void Read_profile(CString path,int load_path) {
  2577.   CWaitCursor wait;
  2578.   CString strSection       = "OptionsValues";
  2579.   CString st;
  2580.   
  2581.   // VΘrification <tmp>
  2582.   if (path=="<tmp>") {     // fichier temporaire
  2583.     if (!tmpf)
  2584.       return;
  2585.     else
  2586.       fflush(tmpf);
  2587.   } else if (path=="<null>") {     // options par dΘfaut
  2588.     path="<mem>";
  2589.     tmpm.deleteAll();              // effacer
  2590.   } else {
  2591.     int pos=path.ReverseFind('\\');
  2592.     if (pos>=0) {
  2593.       CString dir=path.Left(pos);           // enlever winprofile.ini
  2594.       pos=dir.ReverseFind('\\');
  2595.       if (pos>=0) {
  2596.         dir=dir.Left(pos);                  // enlever hts-cache
  2597.         pos=dir.ReverseFind('\\');
  2598.         if (pos>=0) {
  2599.           dialog0->m_projname=dir.Mid(pos+1);
  2600.           dialog0->m_projpath=dir.Left(pos);
  2601.           /*
  2602.           if (this_CWizTab)
  2603.           this_CWizTab->SetActivePage(2);     // page 3
  2604.           */
  2605.         }
  2606.       }
  2607.     }
  2608.   }
  2609.   
  2610.   // checkboxes
  2611.   maintab->m_option1.m_link      = MyGetProfileInt(path,strSection, "Near",0);
  2612.   maintab->m_option1.m_testall   = MyGetProfileInt(path,strSection, "Test",0);
  2613.   maintab->m_option1.m_parseall  = MyGetProfileInt(path,strSection, "ParseAll",1);
  2614.   maintab->m_option1.m_htmlfirst = MyGetProfileInt(path,strSection, "HTMLFirst",0);
  2615.   maintab->m_option3.m_cache     = MyGetProfileInt(path,strSection, "Cache",1);
  2616.   maintab->m_option9.m_norecatch = MyGetProfileInt(path,strSection, "NoRecatch",0);
  2617.   maintab->m_option2.m_dos       = (MyGetProfileInt(path,strSection, "Dos",0) & 1);
  2618.   maintab->m_option2.m_iso9660   = ((MyGetProfileInt(path,strSection, "Dos",0) & 2)>>1);
  2619.   maintab->m_option9.m_index     = MyGetProfileInt(path,strSection, "Index",1);
  2620.   maintab->m_option9.m_index2    = MyGetProfileInt(path,strSection, "WordIndex",0);
  2621.   maintab->m_option9.m_logf      = MyGetProfileInt(path,strSection, "Log",1);
  2622.   maintab->m_option4.m_remt      = MyGetProfileInt(path,strSection, "RemoveTimeout",0);
  2623.   maintab->m_option4.m_rems      = MyGetProfileInt(path,strSection, "RemoveRateout",0);
  2624.   maintab->m_option4.m_ka        = MyGetProfileInt(path,strSection, "KeepAlive",1);
  2625.   maintab->m_option8.m_robots    = MyGetProfileInt(path,strSection, "FollowRobotsTxt",2);
  2626.   maintab->m_option2.m_errpage   = MyGetProfileInt(path,strSection, "NoErrorPages",0);
  2627.   maintab->m_option2.m_external  = MyGetProfileInt(path,strSection, "NoExternalPages",0);
  2628.   maintab->m_option2.m_hidepwd   = MyGetProfileInt(path,strSection, "NoPwdInPages",0);
  2629.   maintab->m_option2.m_hidequery = MyGetProfileInt(path,strSection, "NoQueryStrings",0);
  2630.   maintab->m_option2.m_nopurge   = MyGetProfileInt(path,strSection, "NoPurgeOldFiles",0);
  2631.   maintab->m_option8.m_cookies    = MyGetProfileInt(path,strSection, "Cookies",1);
  2632.   maintab->m_option8.m_checktype  = MyGetProfileInt(path,strSection, "CheckType",1);
  2633.   maintab->m_option8.m_parsejava  = MyGetProfileInt(path,strSection, "ParseJava",1);
  2634.   maintab->m_option8.m_toler      = MyGetProfileInt(path,strSection, "TolerantRequests",0);
  2635.   maintab->m_option8.m_updhack    = MyGetProfileInt(path,strSection, "UpdateHack",1);
  2636.   maintab->m_option8.m_http10     = MyGetProfileInt(path,strSection, "HTTP10",0);
  2637.   maintab->m_option9.m_Cache2     = MyGetProfileInt(path,strSection, "StoreAllInCache",0);
  2638.   maintab->m_option9.m_logtype    = MyGetProfileInt(path,strSection, "LogType",0);
  2639.   
  2640.   // menus
  2641.   maintab->m_option2.m_build   = MyGetProfileInt(path,strSection, "Build",0);
  2642.   maintab->m_option3.m_filter  = MyGetProfileInt(path,strSection, "PrimaryScan",3);
  2643.   maintab->m_option3.m_travel  = MyGetProfileInt(path,strSection, "Travel",1);
  2644.   maintab->m_option3.m_travel2 = MyGetProfileInt(path,strSection, "GlobalTravel",0);
  2645.   maintab->m_option3.m_travel3 = MyGetProfileInt(path,strSection, "RewriteLinks",0);
  2646.   maintab->m_option2.Bopt.m_BuildString = MyGetProfileString(path,strSection, "BuildString","%h%p/%n%q.%t");
  2647.   
  2648.   // champs
  2649.   maintab->m_option5.m_maxhtml =  MyGetProfileString(path,strSection, "MaxHtml");
  2650.   maintab->m_option5.m_othermax=  MyGetProfileString(path,strSection, "MaxOther");
  2651.   maintab->m_option5.m_sizemax =  MyGetProfileString(path,strSection, "MaxAll");
  2652.   maintab->m_option5.m_pausebytes=MyGetProfileString(path,strSection, "MaxWait");  
  2653.   maintab->m_option4.m_connexion= MyGetProfileString(path,strSection, "Sockets");
  2654.   maintab->m_option4.m_retry   =  MyGetProfileString(path,strSection, "Retry");
  2655.   maintab->m_option5.m_maxtime =  MyGetProfileString(path,strSection, "MaxTime");
  2656.   maintab->m_option4.m_timeout =  MyGetProfileString(path,strSection, "TimeOut");
  2657.   maintab->m_option4.m_rate    =  MyGetProfileString(path,strSection, "RateOut");
  2658.   maintab->m_option6.m_user    =  MyGetProfileString(path,strSection, "UserID","Mozilla/4.5 (compatible; HTTrack 3.0x; Windows 98)");
  2659.   maintab->m_option6.m_footer  =  MyGetProfileString(path,strSection, "Footer",HTS_DEFAULT_FOOTER);
  2660.   maintab->m_option5.m_maxrate =  MyGetProfileString(path,strSection, "MaxRate", "25000");
  2661.   maintab->m_option5.m_maxconn =  MyGetProfileString(path,strSection, "MaxConn");
  2662.   maintab->m_option5.m_maxlinks = MyGetProfileString(path,strSection, "MaxLinks");
  2663.   
  2664.   // 7
  2665.   maintab->m_option7.m_url2 = MyGetProfileString(path,strSection, "WildCardFilters","+*.png +*.gif +*.jpg +*.css +*.js -ad.doubleclick.net/*");
  2666.   
  2667.   // 10
  2668.   maintab->m_option10.m_proxy   = MyGetProfileString(path,strSection, "Proxy");
  2669.   maintab->m_option10.m_port    = MyGetProfileString(path,strSection, "Port");
  2670.   maintab->m_option10.m_ftpprox = MyGetProfileInt(path,strSection, "UseHTTPProxyForFTP",1);
  2671.   //
  2672.   maintab->m_option5.m_depth    = MyGetProfileString(path,strSection, "Depth");
  2673.   maintab->m_option5.m_depth2   = MyGetProfileString(path,strSection, "ExtDepth");
  2674.   
  2675.   // 11
  2676.   maintab->m_option11.m_ext1   = MyGetProfileString(path,strSection, "MIMEDefsExt1", "php3,php,php2,asp,jsp,pl,cfm,nsf");
  2677.   maintab->m_option11.m_ext2   = MyGetProfileString(path,strSection, "MIMEDefsExt2");
  2678.   maintab->m_option11.m_ext3   = MyGetProfileString(path,strSection, "MIMEDefsExt3");
  2679.   maintab->m_option11.m_ext4   = MyGetProfileString(path,strSection, "MIMEDefsExt4");
  2680.   maintab->m_option11.m_ext5   = MyGetProfileString(path,strSection, "MIMEDefsExt5");
  2681.   maintab->m_option11.m_ext6   = MyGetProfileString(path,strSection, "MIMEDefsExt6");
  2682.   maintab->m_option11.m_ext7   = MyGetProfileString(path,strSection, "MIMEDefsExt7");
  2683.   maintab->m_option11.m_ext8   = MyGetProfileString(path,strSection, "MIMEDefsExt8");
  2684.   maintab->m_option11.m_mime1   = MyGetProfileString(path,strSection, "MIMEDefsMime1", "text/html");
  2685.   maintab->m_option11.m_mime2   = MyGetProfileString(path,strSection, "MIMEDefsMime2");
  2686.   maintab->m_option11.m_mime3   = MyGetProfileString(path,strSection, "MIMEDefsMime3");
  2687.   maintab->m_option11.m_mime4   = MyGetProfileString(path,strSection, "MIMEDefsMime4");
  2688.   maintab->m_option11.m_mime5   = MyGetProfileString(path,strSection, "MIMEDefsMime5");
  2689.   maintab->m_option11.m_mime6   = MyGetProfileString(path,strSection, "MIMEDefsMime6");
  2690.   maintab->m_option11.m_mime7   = MyGetProfileString(path,strSection, "MIMEDefsMime7");
  2691.   maintab->m_option11.m_mime8   = MyGetProfileString(path,strSection, "MIMEDefsMime8");
  2692.   
  2693.   
  2694.   //st = MyGetProfileString(path,strSection,"WildCardFilters");
  2695.   //strcpybuff(buff_filtres,st);
  2696.   
  2697.   // liens, jokers etc. si mirror merge
  2698.   if (!(path.IsEmpty())) {
  2699.     if (dialog1->m_hWnd == NULL) {    // pas initialisΘ
  2700.       //dialog1->m_depth  = MyGetProfileString(path,strSection,"CurrentDepth");
  2701.       dialog1->m_urls     = MyGetProfileString(path,strSection,"CurrentUrl");
  2702.       dialog1->m_todo     = MyGetProfileInt(path,strSection,"CurrentAction",0);
  2703.       dialog1->m_filelist = MyGetProfileString(path,strSection,"CurrentURLList");
  2704.       /*
  2705.       if (load_path) {
  2706.       CString st;
  2707.       st = MyGetProfileString(path,strSection,"CurrentPath1");
  2708.       if (st != "")
  2709.       dialog1->m_pathlog = st;
  2710.       st = MyGetProfileString(path,strSection,"CurrentPath2");
  2711.       if (st != "")
  2712.       dialog1->m_pathmir = st;
  2713.       }
  2714.       */
  2715.     } else {
  2716.       //st = MyGetProfileString(path,strSection,"CurrentDepth");
  2717.       //dialog1->SetDlgItemText(IDC_depth,st);
  2718.       st = MyGetProfileString(path,strSection,"CurrentUrl");
  2719.       dialog1->SetDlgItemText(IDC_URL,st);
  2720.       int n = MyGetProfileInt(path,strSection,"CurrentAction",0);
  2721.       dialog1->m_ctl_todo.SetCurSel(n);
  2722.       st = MyGetProfileString(path,strSection,"CurrentURLList");
  2723.       dialog1->SetDlgItemText(IDC_filelist,st);
  2724.       /*
  2725.       if (load_path) {
  2726.       st = MyGetProfileString(path,strSection,"CurrentPath1");
  2727.       if (st != "")
  2728.       dialog1->SetDlgItemText(IDC_pathlog,st);
  2729.       st = MyGetProfileString(path,strSection,"CurrentPath2");
  2730.       if (st != "")
  2731.       dialog1->SetDlgItemText(IDC_pthmir,st);
  2732.       }
  2733.       */
  2734.       dialog1->Refresh();
  2735.     }
  2736.   }
  2737.   
  2738. }
  2739.  
  2740. // Initialisation du RAS
  2741. void InitRAS() {
  2742. #if USE_RAS
  2743.   if (!LibRas) {
  2744.     LibRas=new CDynamicRAS();
  2745.     if (LibRas->IsRASLoaded()) 
  2746.       LibRasUse=1;
  2747.     else
  2748.       LibRasUse=0;
  2749.   }
  2750. #endif
  2751. }
  2752.  
  2753. // Reconstruire index gΘnΘral!
  2754. void Build_TopIndex(BOOL check_empty) {
  2755.   CWaitCursor wait;
  2756.  
  2757.   //if (toptemplate_header && toptemplate_body && toptemplate_footer) {
  2758.   {
  2759.     char path[HTS_URLMAXSIZE*2];
  2760.     strcpybuff(path,CShellApp_app->end_path);
  2761.  
  2762.     /* Build top index */
  2763.     hts_buildtopindex(NULL,path, "");
  2764.  
  2765.     /* Check empty dirs and build .whtt */
  2766.     // FILE* fpo=fopen(fconcat(path,"/index.html"),"wb");
  2767.     //if (fpo) {
  2768.     {
  2769.       // verif_backblue(opt, path);    // gΘnΘrer gif
  2770.       //
  2771.       // Header
  2772.       //fprintf(fpo,toptemplate_header,
  2773.       //  "<!-- Mirror and index made by HTTrack Website Copier/"HTTRACK_VERSION" "HTTRACK_AFF_AUTHORS" -->"
  2774.       //  );
  2775.       // chargement de la liste
  2776.       WIN32_FIND_DATA find;
  2777.       HANDLE h = FindFirstFile(CShellApp_app->end_path+"*.*",&find);
  2778.       if (h != INVALID_HANDLE_VALUE) {
  2779.         CString to_delete="";
  2780.         do {
  2781.           if (!(find.dwFileAttributes  & (FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN) ))
  2782.             if (strcmp(find.cFileName,".."))
  2783.               if (strcmp(find.cFileName,"."))
  2784.                 if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  2785.                   int r;
  2786.                   r=CheckDirInfo(CShellApp_app->end_path+find.cFileName);
  2787.                   if ((r>=0) && (r<=3)) {       /* vide, fichiers vides etc */
  2788.                     to_delete+=(CShellApp_app->end_path+find.cFileName+"\n");
  2789.                   } else {      /* non vide */
  2790.                     char iname[HTS_URLMAXSIZE*2],iname2[HTS_URLMAXSIZE*2];
  2791.                     strcpybuff(iname,CShellApp_app->end_path);
  2792.                     strcatbuff(iname,find.cFileName);
  2793.                     strcatbuff(iname,"\\");
  2794.                     strcpybuff(iname2,iname);
  2795.                     strcatbuff(iname,"index.html");
  2796.                     strcatbuff(iname2,"\\hts-cache\\winprofile.ini");
  2797.                     if (fexist(iname)) {
  2798.                       char hname[HTS_URLMAXSIZE*2];
  2799.                       strcpybuff(hname,find.cFileName);
  2800.                       escape_check_url(hname);
  2801.                       // Body
  2802.                       //fprintf(fpo,toptemplate_body,
  2803.                       //  hname,
  2804.                       //  find.cFileName
  2805.                       //  );
  2806.                     }
  2807.                     
  2808.                     if ((fexist(iname)) || (fexist(iname2)) ) {
  2809.                       // vΘrifier existence de .whtt
  2810.                       strcpybuff(iname,CShellApp_app->end_path);
  2811.                       strcatbuff(iname,find.cFileName);
  2812.                       strcatbuff(iname,".whtt");
  2813.                       if (!fexist(iname)) {
  2814.                         FILE* fp=fopen(iname,"wb");
  2815.                         if (fp) fclose(fp);
  2816.                       }
  2817.                       
  2818.                     }
  2819.                   }
  2820.                 } else {    /* effacer .whtt qui ne pointent vers rien */
  2821.                   CString iname=CShellApp_app->end_path+find.cFileName;
  2822.                   if (iname.Right(5).CompareNoCase(".whtt")==0) {
  2823.                     CString rname=iname.Left(iname.GetLength()-5)+"\\index.html";
  2824.                     CString rname2=iname.Left(iname.GetLength()-5)+"\\hts-cache\\winprofile.ini";
  2825.                     if ( (!fexist((char*)LPCTSTR(rname))) && (!fexist((char*)LPCTSTR(rname2))) ) {
  2826.                       remove(iname);
  2827.                     }
  2828.                   }
  2829.                 }
  2830.         } while(FindNextFile(h,&find));
  2831.         FindClose(h);
  2832.         if (check_empty) {
  2833.           while(to_delete.GetLength()>0) {
  2834.             int pos=to_delete.Find('\n');
  2835.             if (pos) {
  2836.               CString path=to_delete.Left(pos);
  2837.               to_delete=to_delete.Mid(pos+1);
  2838.               CString str;
  2839.               str.Format(LANG_DELETEEMPTYCONF,path);
  2840.               if (AfxMessageBox(str,MB_OKCANCEL)==IDOK) {
  2841.                 /* Θliminer au besoin le .whtt */
  2842.                 DeleteFile(path+".whtt");
  2843.                 if (!RemoveEmptyDir(path))
  2844.                   AfxMessageBox(LANG_ERRORDEL);
  2845.               }
  2846.             } else
  2847.               to_delete="";
  2848.           }
  2849.         }
  2850.       }
  2851.       // Footer
  2852.       //fprintf(fpo,toptemplate_footer,
  2853.       //  "<!-- Mirror and index made by HTTrack Website Copier/"HTTRACK_VERSION" "HTTRACK_AFF_AUTHORS" -->"
  2854.       //  );
  2855.       //fclose(fpo);
  2856.     }
  2857.     
  2858.   }
  2859.  
  2860.   /*
  2861.   if (toptemplate_header)
  2862.     freet(toptemplate_header);
  2863.   if (toptemplate_body)
  2864.     freet(toptemplate_body);
  2865.   if (toptemplate_footer)
  2866.     freet(toptemplate_footer);
  2867.   */
  2868. }
  2869.  
  2870. /*
  2871. -1 : error
  2872. 0 : directory is empty
  2873. 1 : empty directories inside
  2874. 2 : empty files inside
  2875. 3 : 1 + 2
  2876. 4 : not empty
  2877. */
  2878. int CheckDirInfo(CString path) {
  2879.   CWaitCursor wait;
  2880.   
  2881.   if (path.Right(1)!="\\")
  2882.     path+="\\";
  2883.   
  2884.   // Pour FindFirstFile/FindNextFile
  2885.   WIN32_FIND_DATA find;
  2886.   HANDLE h = FindFirstFile(path+"*.*",&find);
  2887.   
  2888.   // accessible
  2889.   if (h!=INVALID_HANDLE_VALUE) {
  2890.     int return_code=0;
  2891.     do {
  2892.       if (!(find.dwFileAttributes  & FILE_ATTRIBUTE_SYSTEM )) {
  2893.         if (strcmp(find.cFileName,"..")) {
  2894.           if (strcmp(find.cFileName,".")) {
  2895.             if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  2896.               return_code|=1;
  2897.               int r=CheckDirInfo(path+find.cFileName);
  2898.               if (r==4)
  2899.                 return_code=4;
  2900.               else
  2901.                 return_code|=r;
  2902.             } else {
  2903.               return_code|=2;
  2904.               if ((find.nFileSizeLow) || (find.nFileSizeHigh))
  2905.                 return_code=4;
  2906.             }
  2907.           }
  2908.         }
  2909.       }
  2910.     } while(FindNextFile(h,&find) && !((return_code & 4)) );
  2911.     FindClose(h);
  2912.     return return_code;
  2913.   } else
  2914.     return -1;
  2915. }
  2916.  
  2917. /*
  2918. Remove Empty Dir
  2919. */
  2920. BOOL RemoveEmptyDir(CString path) {
  2921.   CWaitCursor wait;
  2922.   
  2923.   SetCurrentDirectory("C:\\");
  2924.   
  2925.   if (path.Right(1)!="\\")
  2926.     path+="\\";
  2927.   
  2928.   // Pour FindFirstFile/FindNextFile
  2929.   WIN32_FIND_DATA find;
  2930.   HANDLE h = FindFirstFile(path+"*.*",&find);
  2931.   
  2932.   // accessible
  2933.   if (h!=INVALID_HANDLE_VALUE) {
  2934.     do {
  2935.       if (!(find.dwFileAttributes  & FILE_ATTRIBUTE_SYSTEM )) {
  2936.         if (strcmp(find.cFileName,"..")) {
  2937.           if (strcmp(find.cFileName,".")) {
  2938.             if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  2939.               if (!RemoveEmptyDir(path+find.cFileName)) {
  2940.                 FindClose(h);
  2941.                 return 0;
  2942.               }
  2943.             } else {
  2944.               if ((!find.nFileSizeLow) && (!find.nFileSizeHigh))
  2945.                 if (!DeleteFile(path+find.cFileName)) {
  2946.                   FindClose(h);
  2947.                   return 0;
  2948.                 }
  2949.             }
  2950.           }
  2951.         }
  2952.       }
  2953.     } while(FindNextFile(h,&find));
  2954.     FindClose(h);
  2955.     
  2956.     SetCurrentDirectory("C:\\");
  2957.     return RemoveDirectory(path.Left(path.GetLength()-1));
  2958.   } else
  2959.     return 0;
  2960.   return TRUE;
  2961. }
  2962.